--
-- Copyright (C) 2010-2012 the original author or authors.
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
--         http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--

-- SysPDVWeb 02.02.00

-- 39100327004418_create_changelog.sql
--  Create Changelog

-- Default DDL for changelog table that will keep
-- a record of the migrations that have been run.

-- You can modify this to suit your database before
-- running your first migration.

-- Be sure that ID and DESCRIPTION fields exist in
-- BigInteger and String compatible fields respectively.

CREATE TABLE CHANGELOG (
ID NUMERIC(20,0) NOT NULL,
APPLIED_AT VARCHAR(25) NOT NULL,
DESCRIPTION VARCHAR(255) NOT NULL,
PRIMARY KEY (id)
)

INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39100327004418, '2010-09-22 20:34:44', 'create changelog');
GO

SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CARTAO_MOVIMENTO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[CARTAO_MOVIMENTO](
	[CTMID] [int] IDENTITY(1,1) NOT NULL,
	[CTCNUMCAR] [varchar](40) NULL,
	[LOJCOD] [int] NULL,
	[TRNDAT] [datetime] NULL,
	[CXANUM] [int] NULL,
	[TRNSEQ] [varchar](6) NULL,
	[NSU] [varchar](250) NOT NULL,
	[CTMVLR] [numeric](15, 2) NULL,
	[CTMSTA] [int] NULL,
	[FUNCOD] [varchar](6) NULL,
	[CTMNUMPAR] [int] NULL,
	[CTMTIP] [numeric](1, 0) NOT NULL,
	[CTMDATALT] [datetime] NULL,
	[CLICOD] [int] NULL,
 CONSTRAINT [PK_CARTAO_MOVIMENTO] PRIMARY KEY NONCLUSTERED 
(
	[CTMID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY],
 CONSTRAINT [NSU_UNIQUE] UNIQUE NONCLUSTERED 
(
	[NSU] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CEP]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[CEP](
	[CEPCOD] [varchar](8) NOT NULL,
	[CEPBAIR] [varchar](80) NULL,
	[CEPCOMP] [varchar](100) NULL,
	[CEPEST] [varchar](2) NULL,
	[CEPLOG] [varchar](100) NULL,
	[CEPMUN] [varchar](80) NULL,
 CONSTRAINT [SYS_C00128509] PRIMARY KEY NONCLUSTERED 
(
	[CEPCOD] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CHANGELOG]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[CHANGELOG](
	[ID] [numeric](20, 0) NOT NULL,
	[APPLIED_AT] [varchar](25) NOT NULL,
	[DESCRIPTION] [varchar](255) NOT NULL,
 CONSTRAINT [SYS_C00128501] PRIMARY KEY NONCLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CLIENTE_LANCE]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[CLIENTE_LANCE](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[CPF] [varchar](13) NOT NULL,
	[NOME] [varchar](50) NOT NULL,
	[FONE] [varchar](20) NULL,
	[OBSERVACAO] [varchar](200) NULL,
 CONSTRAINT [CLIENTE_LANCE_PK] PRIMARY KEY NONCLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY],
 CONSTRAINT [CLIENTE_LANCE_CPF_UK1] UNIQUE NONCLUSTERED 
(
	[CPF] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DEPENDENTE]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[DEPENDENTE](
	[DEP_ID] [int] IDENTITY(1,1) NOT NULL,
	[DEPBAIR] [varchar](40) NULL,
	[DEPCEP] [varchar](20) NULL,
	[DEPCID] [varchar](30) NULL,
	[DEPCOMP] [varchar](40) NULL,
	[DEPCPF] [varchar](20) NULL,
	[DEPDTCAD] [datetime] NULL,
	[DEPDTNASC] [datetime] NULL,
	[DEPEMAIL] [varchar](60) NULL,
	[DEPEND] [varchar](60) NULL,
	[DEPEST] [varchar](2) NULL,
	[DEPHPAGE] [varchar](60) NULL,
	[DEPNOM] [varchar](60) NULL,
	[DEPNUM] [varchar](12) NULL,
	[DEPOBS] [varchar](255) NULL,
	[DEPSEX] [char](1) NULL,
	[DEPTEL] [varchar](20) NULL,
	[DEPTIP] [varchar](1) NULL,
	[CLICOD] [int] NULL,
 CONSTRAINT [SYS_C00128515] PRIMARY KEY NONCLUSTERED 
(
	[DEP_ID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DEVOLUCAO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[DEVOLUCAO](
	[DEVCOD] [int] NOT NULL,
	[TRNSEQ] [varchar](6) NULL,
	[TRNSEQEQP] [int] NULL,
	[CXANUM] [varchar](3) NULL,
	[TRNDAT] [datetime] NULL,
	[FUNCOD] [int] NULL,
	[LOJCOD] [int] NULL,
	[DEVDAT] [datetime] NULL,
	[DEVVLR] [numeric](15, 2) NULL,
	[DEVACR] [numeric](15, 2) NULL,
	[DEVDCN] [numeric](15, 2) NULL,
	[DEVCLINOM] [varchar](50) NULL,
	[DEVCLICPFCGC] [varchar](15) NULL,
	[DEVCLIRG] [varchar](15) NULL,
	[DEVCLITEL] [varchar](15) NULL,
	[DEVCLIBAI] [varchar](50) NULL,
	[DEVCLIEND] [varchar](50) NULL,
	[DEVCLINUM] [varchar](10) NULL,
	[DEVMOT] [varchar](50) NULL,
	[FUNCODAUT] [int] NULL,
	[DEVSTA] [varchar](1) NULL,
	[DEVTRNSEQ] [varchar](6) NULL,
	[DEVCXANUM] [varchar](3) NULL,
	[DEVTRNDAT] [datetime] NULL,
	[DEVLOG] [varchar](1) NULL,
	[DEVIMPCOD] [varchar](2) NULL,
 CONSTRAINT [SYS_C00128517] PRIMARY KEY NONCLUSTERED 
(
	[DEVCOD] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ECM_CATEGORIA]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[ECM_CATEGORIA](
	[ECTCOD] [int] IDENTITY(1,1) NOT NULL,
	[ECTDES] [varchar](50) NULL,
	[ECTCODPAI] [int] NULL,
	ECTNIV BIGINT,
 CONSTRAINT [PK_ECM_CATEGORIA] PRIMARY KEY NONCLUSTERED 
(
	[ECTCOD] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ECM_FABRICANTE]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[ECM_FABRICANTE](
	[EFBCOD] [int] IDENTITY(1,1) NOT NULL,
	[EFBDES] [varchar](50) NULL,
 CONSTRAINT [PK_ECM_FABRICANTE] PRIMARY KEY NONCLUSTERED 
(
	[EFBCOD] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[NSU_AUTORIZADOR]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[NSU_AUTORIZADOR](
	[SeqID] [int] IDENTITY(1,1) NOT NULL,
	[SeqVal] [varchar](1) NULL,
PRIMARY KEY CLUSTERED 
(
	[SeqID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ECM_PRODUTO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[ECM_PRODUTO](
	[EPRID] [int] IDENTITY(1,1) NOT NULL,
	[EPRDES] [varchar](50) NULL,
	[EPRCAR] [text] NULL,
	[EPRPOR] [varchar](50) NULL,
	[EPRREF] [varchar](200) NULL,
	[ECTCOD] [int] NOT NULL,
	[EFBCOD] [int] NOT NULL,
	[EPRCOD] [int] NOT NULL,
 CONSTRAINT [PK_EPRCOD] PRIMARY KEY NONCLUSTERED 
(
	[EPRID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY],
 CONSTRAINT [EPRCOD_UNIQUE] UNIQUE NONCLUSTERED 
(
	[EPRCOD] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ECM_PRODUTO_NUTRICAO]') AND type in (N'U'))
BEGIN
CREATE TABLE ECM_PRODUTO_NUTRICAO
(
EPNCOD BIGINT IDENTITY (1,1) NOT NULL,
EPNDES varchar(50),
EPNQTD varchar(30),
EPNPERVLRDIA INT,
EPRCOD BIGINT,
ITNCOD BIGINT,
CONSTRAINT [PK_EPNCOD] PRIMARY KEY NONCLUSTERED 
(
	[EPNCOD] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE ECM_ITEM_NUTRICIONAL
(
ITNCOD BIGINT IDENTITY (1,1) NOT NULL,
ITNDES varchar(50),
PRIMARY KEY (ITNCOD)
)
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CARTAO_MOVIMENTO_ESTORNO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[CARTAO_MOVIMENTO_ESTORNO](
	[CTEID] [int] IDENTITY(1,1) NOT NULL,
	[CATNSU] [varchar](255) NULL,
	[CATNSU_ESTORNADO] [varchar](255) NULL,
 CONSTRAINT [PK] PRIMARY KEY NONCLUSTERED 
(
	[CTEID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY],
 CONSTRAINT [UK_NSU] UNIQUE NONCLUSTERED 
(
	[CATNSU] ASC,
	[CATNSU_ESTORNADO] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[REFERENCIA]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[REFERENCIA](
	[REFCOD] [int] IDENTITY(1,1) NOT NULL,
	[REFADM] [varchar](60) NULL,
	[REFAG] [varchar](15) NULL,
	[REFBAI] [varchar](30) NULL,
	[REFCARG] [varchar](20) NULL,
	[REFCEP] [varchar](20) NULL,
	[REFCID] [varchar](30) NULL,
	[REFCONTC] [varchar](20) NULL,
	[REFCONT] [varchar](20) NULL,
	[REFDTADM] [varchar](20) NULL,
	[REFDTABERT] [varchar](10) NULL,
	[REFEND] [varchar](60) NULL,
	[REFEST] [varchar](2) NULL,
	[REFNOM] [varchar](60) NULL,
	[REFNEMP] [varchar](60) NULL,
	[REFNUMCAR] [varchar](30) NULL,
	[REFOBS] [varchar](255) NULL,
	[REFOUTRDA] [varchar](50) NULL,
	[REFSAL] [numeric](15, 2) NULL,
	[REFSETOR] [varchar](30) NULL,
	[REFSEX] [varchar](1) NULL,
	[REFSITCH] [varchar](20) NULL,
	[REFSITSPC] [varchar](20) NULL,
	[REFTEL1] [varchar](20) NULL,
	[REFTEL2] [varchar](20) NULL,
	[REFTIP] [varchar](1) NULL,
	[REFVALICAR] [varchar](10) NULL,
	[CLICOD] [int] NULL,
 CONSTRAINT [SYS_C00128609] PRIMARY KEY NONCLUSTERED 
(
	[REFCOD] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ESTOQUE]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[ESTOQUE](
	[ESTID] [int] IDENTITY(1,1) NOT NULL,
	[PROCOD] [int] NOT NULL,
	[LOJCOD] [int] NULL,
	[ESTATU] [numeric](15, 3) NULL,
	[ESTDATULTENT] [datetime] NULL,
	[ESTDATULTSAI] [datetime] NULL,
	[ESTQTDULTENT] [numeric](15, 3) NULL,
	[ESTQTDULTSAI] [numeric](15, 3) NULL,
 CONSTRAINT [SYS_C00128520] PRIMARY KEY NONCLUSTERED 
(
	[ESTID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SANGRIA_CONCILIACAO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[SANGRIA_CONCILIACAO](
	[ID] [int] NOT NULL,
	[TRNSEQ] [varchar](6) NULL,
	[CXANUM] [varchar](3) NULL,
	[TRNDAT] [datetime] NULL,
	[FUNCODOP] [int] NULL,
	[FUNCODAUT] [int] NULL,
	[FUNCODCON] [int] NULL,
	[FZDCOD] [int] NULL,
	[SGCVLR] [numeric](15, 2) NOT NULL,
	[SGCSTATUS] [varchar](1) NULL,
	[LOJCOD] [int] NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SECAO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[SECAO](
	[SECCOD] [int] NULL,
	[SECDES] [varchar](60) NULL,
	[SECID] [int] IDENTITY(1,1) NOT NULL,
 CONSTRAINT [SECID] PRIMARY KEY NONCLUSTERED 
(
	[SECID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SP_FIDELIZACAO_GERA_NSU]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE procedure [dbo].[SP_FIDELIZACAO_GERA_NSU]
as
begin
      declare @NewSeqValue int
      set NOCOUNT ON
      insert into NSU_FIDELIZACAO default values
      set @NewSeqValue = scope_identity()
      delete from NSU_FIDELIZACAO WITH (READPAST)

return @NewSeqValue

end' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[STATUS]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[STATUS](
	[STACOD] [int] NOT NULL,
	[STABLC] [int] NULL,
	[STADES] [varchar](60) NULL,
	[STATIPBLOQ] [varchar](4) NULL,
	[STA_ORIGEM_ALTERACAO] [varchar](11) NULL,
	[STA_DATA_ALTERACAO] [datetime] NULL,
	[STA_CHAVE_RETAGUARDA] [int] NULL,
	[STA_VERSAO_RETAGUARDA] [int] NULL,
 CONSTRAINT [SYS_C00128614] PRIMARY KEY NONCLUSTERED 
(
	[STACOD] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[NSU_FIDELIZACAO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[NSU_FIDELIZACAO](
	[SeqID] [int] IDENTITY(1,1) NOT NULL,
	[SeqVal] [varchar](1) NULL,
PRIMARY KEY CLUSTERED 
(
	[SeqID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SUBGRUPO_PRODUTO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[SUBGRUPO_PRODUTO](
	[SGPCOD] [int] NOT NULL,
	[SGPDES] [varchar](80) NOT NULL,
	[GRPCOD] [int] NOT NULL,
	[SGPID] [int] IDENTITY(1,1) NOT NULL,
	[SECCOD] [int] NULL,
 CONSTRAINT [SYS_C00128618] PRIMARY KEY NONCLUSTERED 
(
	[SGPID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY],
 CONSTRAINT [SUBGRUPO_UNIQUE] UNIQUE NONCLUSTERED 
(
	[GRPCOD] ASC,
	[SGPCOD] ASC,
	[SECCOD] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TABELA]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TABELA](
	[TBLCOD] [int] NOT NULL,
	[TBLCLS] [varchar](100) NULL,
	[TBLDES] [varchar](60) NULL,
 CONSTRAINT [SYS_C00128620] PRIMARY KEY NONCLUSTERED 
(
	[TBLCOD] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FORNECEDOR]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[FORNECEDOR](
	[FORCOD] [int] NOT NULL,
	[FORDES] [varchar](40) NULL,
	[FOREND] [varchar](45) NULL,
	[FORBAI] [varchar](20) NULL,
	[FORCID] [varchar](20) NULL,
	[FOREST] [char](2) NULL,
	[FORTEL] [varchar](15) NULL,
	[FORFAX] [varchar](15) NULL,
	[FORCEP] [varchar](50) NULL,
	[FORNUM] [char](6) NULL,
	[FORCMP] [varchar](15) NULL,
	[FORCON] [varchar](15) NULL,
	[FOROBS] [varchar](70) NULL,
	[FORFAN] [varchar](15) NULL,
	[FORCGC] [varchar](14) NULL,
	[FORCGF] [varchar](20) NULL,
	[FORTABPRZ] [char](3) NULL,
	[FORPRZ] [numeric](15, 2) NULL,
	[FOREMAIL] [varchar](70) NULL,
	[FORTRANS] [char](1) NULL,
 CONSTRAINT [PRIMARYKEY] PRIMARY KEY NONCLUSTERED 
(
	[FORCOD] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TIPOTRANSACAO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TIPOTRANSACAO](
	[TPTRCOD] [varchar](1) NOT NULL,
	[TPTRDES] [varchar](65) NULL,
 CONSTRAINT [SYS_C00128628] PRIMARY KEY NONCLUSTERED 
(
	[TPTRCOD] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TIPO_DOCUMENTO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TIPO_DOCUMENTO](
	[TPDCOD] [int] NOT NULL,
	[TPDDES] [varchar](60) NULL,
 CONSTRAINT [SYS_C00128622] PRIMARY KEY NONCLUSTERED 
(
	[TPDCOD] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GRUPO_PRODUTO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[GRUPO_PRODUTO](
	[GRPCOD] [int] NOT NULL,
	[GRPDES] [varchar](60) NULL,
	[SECCOD] [int] NOT NULL,
	[GRPID] [int] IDENTITY(1,1) NOT NULL,
 CONSTRAINT [SYS_C00128536] PRIMARY KEY NONCLUSTERED 
(
	[GRPID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY],
 CONSTRAINT [GRUPO_SECAO_UN] UNIQUE NONCLUSTERED 
(
	[GRPCOD] ASC,
	[SECCOD] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TIPO_PAGAMENTO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TIPO_PAGAMENTO](
	[TPPCOD] [int] NOT NULL,
	[TPPDES] [varchar](60) NULL,
	[TPPVLRMAX] [numeric](2, 0) NULL,
 CONSTRAINT [SYS_C00128624] PRIMARY KEY NONCLUSTERED 
(
	[TPPCOD] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TIPO_RECEBIMENTO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TIPO_RECEBIMENTO](
	[TPRCOD] [int] NOT NULL,
	[TPRDES] [varchar](30) NULL,
	[TPRTIP] [char](1) NULL,
	[TPRDCN] [numeric](15, 2) NULL,
	[TPRNUMAUT] [char](1) NULL,
	[TPRPRZREC] [int] NULL,
	[TPRPRZJUR] [int] NULL,
	[TPRPRZMUL] [int] NULL,
	[TPRPERJUR] [numeric](15, 4) NULL,
	[TPRPERMUL] [numeric](15, 2) NULL,
	[TPRTIPJUR] [char](1) NULL,
	[TPRIMPDOC] [char](1) NULL,
	[TPRNUMVIA] [char](1) NULL,
	[TPRVLRFIX] [numeric](15, 2) NULL,
 CONSTRAINT [SYS_C00128626] PRIMARY KEY NONCLUSTERED 
(
	[TPRCOD] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GRUPO_USUARIO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[GRUPO_USUARIO](
	[GRPCOD] [int] NOT NULL,
	[GRPATIV] [varchar](20) NULL,
	[GRPNOM] [varchar](60) NOT NULL,
	[GRPWEBSERVER] [int] NULL,
 CONSTRAINT [SYS_C00128539] PRIMARY KEY NONCLUSTERED 
(
	[GRPCOD] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TIPO_TRANSACAO_CARTAO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TIPO_TRANSACAO_CARTAO](
	[TTCID] [int] NOT NULL,
	[TTCDES] [varchar](65) NULL,
 CONSTRAINT [SYS_C00128734] PRIMARY KEY NONCLUSTERED 
(
	[TTCID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HOLDING]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[HOLDING](
	[HOLCOD] [int] NOT NULL,
	[HOLDES] [varchar](60) NULL,
 CONSTRAINT [SYS_C00128541] PRIMARY KEY NONCLUSTERED 
(
	[HOLCOD] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TRANSACAO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TRANSACAO](
	[LOJCOD] [int] NOT NULL,
	[TRNDAT] [datetime] NOT NULL,
	[CXANUM] [varchar](3) NOT NULL,
	[TRNSEQ] [varchar](6) NOT NULL,
	[TRNACR] [numeric](15, 2) NULL,
	[TRNCARFID] [varchar](19) NULL,
	[CLICOD] [int] NULL,
	[FUNCOD] [int] NULL,
	[TRNIMPCOD] [varchar](2) NULL,
	[TRNSEQEQP] [int] NULL,
	[TRNHORFIN] [datetime] NULL,
	[TRNHORINI] [datetime] NULL,
	[TRNDATVEN] [datetime] NULL,
	[TRNDCN] [numeric](15, 2) NULL,
	[TRNFCD] [varchar](1) NULL,
	[TRNFUNAUT] [int] NULL,
	[TRNHOR] [varchar](4) NULL,
	[TRNIMPFIS] [varchar](1) NULL,
	[TRNLOGWEB] [varchar](1) NULL,
	[CXANUMEQP] [varchar](3) NULL,
	[TRNQTDITECAN] [numeric](15, 2) NULL,
	[TRNQTDITEVDA] [numeric](15, 2) NULL,
	[TRNQTDUNDCAN] [numeric](15, 2) NULL,
	[TRNQTDUNDVDA] [numeric](15, 2) NULL,
	[TRNOPRSEQ] [varchar](1) NULL,
	[TRNSEREQP] [varchar](20) NULL,
	[TRNTIP] [varchar](1) NULL,
	[TRNTIPPRC] [varchar](1) NULL,
	[TRNTRF] [varchar](1) NULL,
	[TRNVLR] [numeric](15, 2) NULL,
	[TRNVLRGTCDF] [varchar](20) NULL,
	[TRNVLRITECAN] [numeric](15, 2) NULL,
	[TRNVER] [varchar](6) NULL,
 CONSTRAINT [SYS_C00128633] PRIMARY KEY NONCLUSTERED 
(
	[LOJCOD] ASC,
	[TRNDAT] ASC,
	[CXANUM] ASC,
	[TRNSEQ] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[IMPOSTOS_FEDERAIS]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[IMPOSTOS_FEDERAIS](
	[IMPFEDID] [int] IDENTITY(1,1) NOT NULL,
	[IMPFEDSIM] [char](1) NOT NULL,
	[IMPFEDDES] [varchar](20) NULL,
	[IMPFEDINC] [char](1) NULL,
	[IMPFEDALQ] [numeric](15, 4) NULL,
	[IMPFEDRET] [numeric](15, 4) NULL,
	[IPMFEDOBS] [varchar](20) NULL,
	[IMPFEDTIP] [char](1) NULL,
 CONSTRAINT [PK_IMPOSTO_FEDERAL] PRIMARY KEY NONCLUSTERED 
(
	[IMPFEDID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY],
 CONSTRAINT [COD_IMPOSTO_FEDERAL] UNIQUE NONCLUSTERED 
(
	[IMPFEDSIM] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TRANSACAOITEMTEFDLL]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TRANSACAOITEMTEFDLL](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[TRNSEQ] [varchar](6) NOT NULL,
	[CXANUM] [varchar](3) NOT NULL,
	[TRNDAT] [datetime] NOT NULL,
	[TEFSEQTRN] [varchar](10) NOT NULL,
	[TEFDATTRN] [varchar](8) NOT NULL,
	[TEFHORTRN] [varchar](6) NOT NULL,
	[TEFTC_600] [varchar](8) NULL,
	[TEFTC_601] [varchar](13) NULL,
	[TEFTC_602] [varchar](13) NULL,
	[TEFTC_603] [varchar](13) NULL,
	[TEFTC_604] [varchar](13) NULL,
	[TEFTC_605] [varchar](8) NULL,
	[TEFTC_606] [varchar](60) NULL,
	[TEFTC_607] [varchar](2) NOT NULL,
	[TEFTC_611] [varchar](15) NULL,
	[TEFTC_612] [varchar](1) NULL,
	[TEFTC_614] [varchar](15) NULL,
	[TEFTC_623] [varchar](15) NULL,
	[TEFTC_624] [varchar](60) NULL,
	[LOJCOD] [int] NULL,
 CONSTRAINT [SYS_C00128642] PRIMARY KEY NONCLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TRANSACAOTEFDLL]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TRANSACAOTEFDLL](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[TRNSEQ] [varchar](6) NOT NULL,
	[CXANUM] [varchar](3) NOT NULL,
	[TRNDAT] [datetime] NOT NULL,
	[LOJCOD] [int] NULL,
	[TEFSEQTRN] [varchar](10) NOT NULL,
	[TEFDATTRN] [varchar](8) NOT NULL,
	[TEFHORTRN] [varchar](6) NOT NULL,
	[TEFECFCOD] [varchar](2) NULL,
	[TEFFZDDES] [varchar](20) NULL,
	[TEFFZDVLR] [numeric](15, 2) NULL,
	[TEFTC_100] [varchar](4) NULL,
	[TEFTC_105] [varchar](14) NULL,
	[TEFTC_110] [varchar](4) NULL,
	[TEFTC_120] [varchar](60) NULL,
	[TEFTC_121] [ntext] NULL,
	[TEFTC_122] [ntext] NULL,
	[TEFTC_130] [varchar](13) NULL,
	[TEFTC_131] [varchar](5) NULL,
	[TEFTC_132] [varchar](5) NULL,
	[TEFTC_133] [varchar](6) NULL,
	[TEFTC_134] [varchar](15) NULL,
	[TEFTC_135] [varchar](15) NULL,
	[TEFTC_136] [varchar](6) NULL,
	[TEFTC_140] [varchar](3) NULL,
	[TEFTC_145] [varchar](8) NULL,
	[TEFTC_501] [varchar](1) NULL,
	[TEFTC_502] [varchar](14) NULL,
	[TEFTC_503] [varchar](14) NULL,
	[TEFTC_504] [varchar](6) NULL,
	[TEFTC_505] [varchar](3) NULL,
	[TEFTC_506] [varchar](8) NULL,
	[TEFTC_507] [varchar](1) NULL,
	[TEFTC_508] [varchar](2) NULL,
	[TEFTC_509] [varchar](1) NULL,
	[TEFTC_510] [varchar](1) NULL,
	[TEFTC_511] [varchar](3) NULL,
	[TEFTC_512] [varchar](19) NULL,
	[TEFTC_513] [varchar](8) NULL,
	[TEFTC_514] [varchar](4) NULL,
	[TEFTC_590] [varchar](20) NULL,
	[TEFTC_591] [varchar](13) NULL,
	[TEFTC_592] [varchar](15) NULL,
	[TEFTC_593] [varchar](3) NULL,
	[TEFTC_594] [varchar](8) NULL,
	[TEFTC_608] [varchar](4) NULL,
	[TEFTC_609] [varchar](13) NULL,
	[TEFTC_610] [varchar](13) NULL,
	[TEFTC_613] [varchar](30) NULL,
	[TEFTC_620] [varchar](15) NULL,
	[TEFTC_621] [varchar](15) NULL,
	[TEFTC_622] [varchar](13) NULL,
	[TEFTC_700] [varchar](4) NULL,
	[TEFTC_701] [varchar](30) NULL,
	[TEFTC_702] [varchar](30) NULL,
	[TEFTIPOPE] [varchar](3) NULL,
	[TEFTIP] [varchar](1) NULL,
	[TEFSEQFZD] [varchar](3) NULL,
	[TEFSEQEQP] [int] NULL,
	[TEFSTA] [varchar](1) NULL,
 CONSTRAINT [SYS_C00128650] PRIMARY KEY NONCLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TRIBUTACAO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TRIBUTACAO](
	[TRBID] [char](3) NOT NULL,
	[TRBSIM] [char](1) NULL,
	[TRBCOD] [char](2) NULL,
	[TRBDES] [varchar](20) NULL,
	[TRBALQ] [numeric](15, 2) NULL,
	[TRBRED] [numeric](15, 2) NULL,
	[TRBTABB] [char](3) NULL,
	[TRBINC] [numeric](15, 2) NULL,
	[TRBOBS] [varchar](80) NULL,
	[TRBREDINT] [numeric](15, 2) NULL,
	[TRBOBSINT] [varchar](80) NULL,
	[TRBSISIF] [char](1) NULL,
	[TRBREDSISIF] [numeric](15, 2) NULL,
	[TRBOBSSISIF] [varchar](80) NULL,
	[TRBSIMECF] [char](1) NULL,
	[TRBALQECF] [numeric](15, 2) NULL,
 CONSTRAINT [SYS_C00128652] PRIMARY KEY NONCLUSTERED 
(
	[TRBID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TROCA]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TROCA](
	[TRCCOD] [char](6) NOT NULL,
	[TRNSEQ] [char](6) NULL,
	[TRNSEQEQP] [int] NULL,
	[CXANUM] [char](3) NULL,
	[TRNDAT] [datetime] NULL,
	[FUNCOD] [char](6) NULL,
	[LOJCOD] [char](4) NOT NULL,
	[TRCDAT] [datetime] NULL,
	[TRCVLR] [numeric](15, 2) NULL,
	[TRCACR] [numeric](15, 2) NULL,
	[TRCDCN] [numeric](15, 2) NULL,
	[TRCCLINOM] [varchar](50) NULL,
	[TRCCLICPFCGC] [varchar](15) NULL,
	[TRCCLIRG] [varchar](15) NULL,
	[TRCCLITEL] [varchar](15) NULL,
	[TRCCLIBAI] [varchar](50) NULL,
	[TRCCLIEND] [varchar](50) NULL,
	[TRCCLINUM] [varchar](10) NULL,
	[TRCMOT] [varchar](50) NULL,
	[FUNCODAUT] [char](6) NULL,
	[TRCSTA] [char](1) NULL,
	[TRCTRNDAT] [datetime] NULL,
	[TRCTRNSEQ] [char](6) NULL,
	[TRCCXANUM] [char](3) NULL,
	[TRCLOG] [char](1) NULL,
	[TRCIMPCOD] [char](2) NULL,
	[TRCFUN] [char](6) NULL,
 CONSTRAINT [TROCA_PK] PRIMARY KEY NONCLUSTERED 
(
	[TRCCOD] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TROCA_FINALIZACAO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TROCA_FINALIZACAO](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[TRNSEQ] [char](6) NULL,
	[CXANUM] [char](3) NULL,
	[TRNDAT] [datetime] NULL,
	[FZDCODORI] [char](3) NULL,
	[FZDCODDES] [char](3) NULL,
	[FZDVLR] [numeric](15, 2) NULL,
	[FUNCODAUT] [char](6) NULL,
	[TRNSEQTRC] [char](6) NULL,
	[CXANUMTRC] [char](3) NULL,
	[TRNDATTRC] [datetime] NULL,
	[FZDSEQTRC] [char](3) NULL,
	[FZDSOLPLATRC] [char](1) NULL,
	[FZDGERCTARECTRC] [char](1) NULL,
	[TRNSEQEQPTRC] [int] NULL,
	[CXANUMEQPTRC] [char](3) NULL,
	[FZDCTRVAL] [numeric](15, 2) NULL,
	[FZDTRCCTR] [char](1) NULL,
	[FZDFUCCOD] [char](4) NULL,
	[LOJCOD] [int] NULL,
 CONSTRAINT [TROCA_FINALIZACAO_PK] PRIMARY KEY NONCLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ITEM_TROCA]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[ITEM_TROCA](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[TRCCOD] [char](6) NOT NULL,
	[PROCOD] [char](14) NOT NULL,
	[ITTQTD] [numeric](15, 3) NULL,
	[ITTTIPPRC] [char](1) NULL,
	[ITTVLRUNI] [numeric](15, 2) NULL,
	[ITTVLRDCN] [numeric](15, 2) NULL,
	[ITTVLRTOT] [numeric](15, 2) NULL,
	[ITTCOMVEN] [numeric](15, 2) NULL,
	[ITTCOMRED] [numeric](15, 4) NULL,
	[PROCTREST] [char](1) NULL,
	[PROCTRSER] [char](1) NULL,
	[FUNCOD] [char](6) NULL,
	[ITTSERPRO] [varchar](20) NULL,
 CONSTRAINT [SYS_C00128567] PRIMARY KEY NONCLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TROCO_PREMIADO_REMESSA]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TROCO_PREMIADO_REMESSA](
	[TPRNUMREM] [int] NOT NULL,
	[TPRDATGER] [datetime] NULL,
	[TPRTOTNUMREG] [int] NULL,
 CONSTRAINT [PK_TROCO_PREMIADO_REMESSA] PRIMARY KEY NONCLUSTERED 
(
	[TPRNUMREM] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TROCO_PREMIADO_RETORNO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TROCO_PREMIADO_RETORNO](
	[TPTNUM] [int] NOT NULL,
	[TPTDAT] [datetime] NOT NULL,
	[TPTTOTNUM] [int] NOT NULL,
	[TPTPERINI] [datetime] NULL,
	[TPTPERFIM] [datetime] NULL,
 CONSTRAINT [PK_TROCO_PREMIADO_RETORNO] PRIMARY KEY NONCLUSTERED 
(
	[TPTNUM] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[LANCE_UNICO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[LANCE_UNICO](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[CODIGO_SMS] [varchar](50) NOT NULL,
	[HASH] [varchar](32) NOT NULL,
	[LOJA_CODIGO] [int] NULL,
	[DATA] [datetime] NULL,
	[ECF] [int] NULL,
	[COO] [int] NULL,
	[CPF_CLIENTE] [varchar](15) NOT NULL,
	[CRIADO_EM] [datetime] NULL,
	[VALOR_ENCRIPTADO] [varchar](32) NOT NULL,
 CONSTRAINT [LANCE_UNICO_PK] PRIMARY KEY NONCLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY],
 CONSTRAINT [LANCE_UNICO_HASH_UK1] UNIQUE NONCLUSTERED 
(
	[HASH] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY],
 CONSTRAINT [LANCE_UNICO_SMS_UK1] UNIQUE NONCLUSTERED 
(
	[CODIGO_SMS] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UNIDADE]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[UNIDADE](
	[UNDID] [int] IDENTITY(1,1) NOT NULL,
	[UNDCOD] [varchar](3) NOT NULL,
	[UNDDES] [varchar](15) NULL,
	[UNDFATREF] [numeric](15, 2) NULL,
 CONSTRAINT [UNDEID] PRIMARY KEY NONCLUSTERED 
(
	[UNDID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[LIMITE_CREDITO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[LIMITE_CREDITO](
	[CLICOD] [int] NOT NULL,
	[TPDCOD] [int] NOT NULL,
	[LMCUTIL] [numeric](15, 2) NULL,
	[LMCVAL] [numeric](15, 2) NULL,
 CONSTRAINT [SYS_C00128576] PRIMARY KEY NONCLUSTERED 
(
	[CLICOD] ASC,
	[TPDCOD] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USUARIO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[USUARIO](
	[FUNCOD] [int] NOT NULL,
	[USUNOM] [varchar](60) NOT NULL,
	[USUSEN] [varchar](60) NOT NULL,
 CONSTRAINT [SYS_C00128675] PRIMARY KEY NONCLUSTERED 
(
	[FUNCOD] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PARAMETRO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[PARAMETRO](
	[PARCOD] [int] NOT NULL,
	[PARCRITICA] [varchar](30) NULL,
	[PARDES] [varchar](80) NULL,
	[PAROBS] [varchar](250) NULL,
	[PARSTA] [varchar](1) NULL,
	[PARVALID] [varchar](1) NULL,
 CONSTRAINT [SYS_C00128585] PRIMARY KEY NONCLUSTERED 
(
	[PARCOD] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PARAMETRO_FIDELIZACAO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[PARAMETRO_FIDELIZACAO](
	[PRF_ID] [int] NOT NULL,
	[PRF_VALOR] [int] NULL,
 CONSTRAINT [PARAMETRO_FIDELIZACAO_PK] PRIMARY KEY NONCLUSTERED 
(
	[PRF_ID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MENU]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[MENU](
	[MEN_ID] [int] NOT NULL,
	[MENPAI] [int] NULL,
	[MENNOME] [varchar](60) NOT NULL,
	[MENORDEM] [int] NULL,
	[MENURL] [varchar](60) NULL,
	[MENROLE] [varchar](60) NULL,
 CONSTRAINT [SYS_C00128583] PRIMARY KEY NONCLUSTERED 
(
	[MEN_ID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PREMIO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[PREMIO](
	[PRE_ID] [int] IDENTITY(1,1) NOT NULL,
	[PRE_CODIGO] [int] NOT NULL,
	[PRE_DESCRICAO] [varchar](20) NOT NULL,
	[PRE_REQUER_PONTOS] [int] NULL,
	[PRE_SALDO] [varchar](20) NULL,
	[PRE_DATA_CADASTRO] [datetime] NULL,
 CONSTRAINT [PREMIO_PK] PRIMARY KEY NONCLUSTERED 
(
	[PRE_ID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY],
 CONSTRAINT [PREMIO_UK_CODIGO] UNIQUE NONCLUSTERED 
(
	[PRE_CODIGO] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PRODUTO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[PRODUTO](
	[PROCOD] [int] NOT NULL,
	[PROCODINT] [char](8) NULL,
	[PRODES] [varchar](45) NULL,
	[PRODESRDZ] [varchar](20) NULL,
	[SECCOD] [int] NULL,
	[TRBID] [char](3) NULL,
	[PROUNID] [varchar](3) NULL,
	[PROPESVAR] [char](1) NULL,
	[PROCOMTIP] [char](1) NULL,
	[PROCOMCAP] [numeric](15, 2) NULL,
	[PROCOMPRO] [numeric](15, 2) NULL,
	[PROCOMVEN] [numeric](15, 2) NULL,
	[PROVLD] [char](3) NULL,
	[PROFRTLOJ] [char](1) NULL,
	[PROESTMIN] [numeric](15, 3) NULL,
	[PROESTMAX] [numeric](15, 3) NULL,
	[FORCOD] [int] NULL,
	[PROQTDETQ] [int] NULL,
	[PRONUMSER] [char](1) NULL,
	[PROFLGALT] [char](1) NULL,
	[PROTABA] [char](1) NULL,
	[PROBONTIP] [char](1) NULL,
	[PROBONFAT] [numeric](15, 3) NULL,
	[PROCTREST] [char](1) NULL,
	[PROESP] [char](1) NULL,
	[PROCOMP] [char](1) NULL,
	[PROCTRVLD] [char](1) NULL,
	[PROENVBAL] [char](1) NULL,
	[PRODATCADINC] [datetime] NULL,
	[PRODATCADALT] [datetime] NULL,
	[FUNCOD] [int] NULL,
	[PROMIX] [char](1) NULL,
	[PRODESVAR] [char](1) NULL,
	[PROEND] [varchar](20) NULL,
	[GRPCOD] [int] NULL,
	[SGPCOD] [int] NULL,
	[PROITEEMB] [numeric](15, 3) NULL,
	[PROCSTMED] [numeric](15, 2) NULL,
	[PROQTDMAXVDA] [numeric](15, 3) NULL,
	[PROPESBRT] [numeric](9, 3) NULL,
	[PROPESLIQ] [numeric](9, 3) NULL,
	[PROFORLIN] [char](1) NULL,
	[PRODATFORLIN] [datetime] NULL,
	[PROUNDCMP] [char](5) NULL,
	[LOCCOD] [int] NULL,
	[PROUNDREF] [char](5) NULL,
	[PROMEDREF] [numeric](15, 3) NULL,
	[PRODID] [int] IDENTITY(1,1) NOT NULL,
	[PROIPI] [numeric](15, 2) NULL,
	[PROTIPIPI] [char](1) NULL,
	[PROVLRAGR] [numeric](15, 2) NULL,
	[PROTIPAGR] [char](1) NULL,
	[PROPRCVAR] [char](1) NULL,
	[PROIAT] [char](1) NULL,
	[PROIPPT] [char](1) NULL,
	[PRONCM] [varchar](20) NULL,
	[PROFIN] [char](1) NULL,
 CONSTRAINT [PK_PRODUTO] PRIMARY KEY NONCLUSTERED 
(
	[PRODID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PRODUTOAUX]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[PRODUTOAUX](
	[PROCODAUX] [varchar](20) NOT NULL,
	[PROCOD] [int] NULL,
 CONSTRAINT [SYS_C00128598] PRIMARY KEY NONCLUSTERED 
(
	[PROCODAUX] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PRODUTO_FORNECEDOR]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[PRODUTO_FORNECEDOR](
	[PROCOD] [int] NOT NULL,
	[FORCOD] [int] NULL,
	[PRFREFFOR] [varchar](20) NULL,
	[PRFUNID] [varchar](3) NULL,
	[PRFQTD] [int] NULL,
	[PRFNIVEL] [char](1) NULL,
	[PRFID] [int] IDENTITY(1,1) NOT NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PROPRIO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[PROPRIO](
	[PRPCOD] [int] NOT NULL,
	[PRPDES] [varchar](80) NULL,
	[PRPFAN] [varchar](30) NULL,
	[PRPCGC] [varchar](14) NULL,
	[PRPIERG] [varchar](18) NULL,
	[PRPEND] [varchar](40) NULL,
	[PRPBAI] [varchar](20) NULL,
	[PRPMUN] [varchar](20) NULL,
	[PRPUF] [varchar](2) NULL,
	[PRPTEL] [varchar](12) NULL,
	[PRPFAX] [varchar](15) NULL,
	[PRPCEP] [varchar](10) NULL,
	[PRPNUM] [varchar](6) NULL,
	[PRPCMP] [varchar](15) NULL,
	[PRPESP] [varchar](40) NULL,
	[PRPEMAIL] [varchar](80) NULL,
	[PRPCHV] [varchar](42) NULL,
	[PRPCHVANT] [varchar](42) NULL,
	[PRPVER] [varchar](6) NULL,
	[PRPEMAILSUP] [varchar](30) NULL,
	[PRPHOST] [varchar](15) NULL,
	[PRPPORT] [varchar](4) NULL,
	[PRPUSRNOM] [varchar](30) NULL,
	[PRPUSRSEN] [varchar](32) NULL,
	[PRPUSRAUT] [char](1) NULL,
	[PRPSIG] [varchar](3) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[RAMO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[RAMO](
	[RAMCOD] [int] NOT NULL,
	[RAMDES] [varchar](60) NULL,
 CONSTRAINT [SYS_C00128601] PRIMARY KEY NONCLUSTERED 
(
	[RAMCOD] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[AUTORIZACAO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[AUTORIZACAO](
	[AUT_ID] [int] IDENTITY(1,1) NOT NULL,
	[AUTCOD] [varchar](10) NULL,
	[AUTCOO] [varchar](6) NULL,
	[AUTDAT] [datetime] NULL,
	[AUTDESC] [varchar](60) NULL,
	[AUTCXANUM] [varchar](4) NULL,
	[AUTVAL] [numeric](15, 2) NULL,
	[LOJCOD] [int] NULL,
	[CLICOD] [int] NULL,
	[FUNAUTCOD] [int] NULL,
	[FUNCOD] [int] NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FINALIZACAO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[FINALIZACAO](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[FZCATUCRE] [varchar](1) NULL,
	[AGECOD] [varchar](4) NULL,
	[FZDCODORI] [varchar](3) NULL,
	[PLACOD] [varchar](2) NULL,
	[FZCDATVEN] [datetime] NULL,
	[FZCDCNMDA] [numeric](15, 2) NULL,
	[FZCEMICHQ] [varchar](15) NULL,
	[FZCESP] [varchar](1) NULL,
	[FZCGERCTAREC] [varchar](1) NULL,
	[FZCGERFID] [varchar](1) NULL,
	[FZCJURPLA] [numeric](15, 2) NULL,
	[FZCLERCMC7] [varchar](1) NULL,
	[FZCCARNUM] [varchar](20) NULL,
	[PLCRED] [varchar](4) NULL,
	[FZCQTDPAR] [varchar](3) NULL,
	[FZCSGRDET] [varchar](1) NULL,
	[FZCSEQ] [varchar](3) NULL,
	[FZCSOLPLA] [varchar](1) NULL,
	[FZCTEXT1] [varchar](15) NULL,
	[FZCTEXT2] [varchar](15) NULL,
	[FZCTEXT3] [varchar](15) NULL,
	[FZCTEXT4] [varchar](15) NULL,
	[FZCTIP] [varchar](1) NULL,
	[FZCTRCCTR] [varchar](1) NULL,
	[FZCCTRVAL] [numeric](15, 2) NULL,
	[FZCTRCDOA] [numeric](15, 2) NULL,
	[FZCVLR] [numeric](15, 2) NULL,
	[FZCVERLIM] [varchar](1) NULL,
	[FZDCOD] [int] NULL,
	[LOJCOD] [int] NULL,
	[TRNDAT] [datetime] NULL,
	[CXANUM] [varchar](3) NULL,
	[TRNSEQ] [varchar](6) NULL,
	[CLICOD] [int] NULL,
	[FZDCNTIMP] [varchar](1) NULL,
	[SEQFZD] [varchar](3) NULL,
	[FZDNUMVLC] [varchar](10) NULL,
 CONSTRAINT [SYS_C00128527] PRIMARY KEY NONCLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FIDELIZACAO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[FIDELIZACAO](
	[FID_ID] [int] IDENTITY(1,1) NOT NULL,
	[FID_NUMERO_CARTAO] [varchar](20) NOT NULL,
	[CLICOD] [int] NOT NULL,
	[FID_SALDO_PONTOS] [int] NOT NULL DEFAULT ((0)),
	[FID_STATUS] [varchar](20) NOT NULL,
	[FID_DATA_CADASTRO] [datetime] NOT NULL,
	[FID_DATA_CANCELADO] [datetime] NULL,
 CONSTRAINT [FIDELIZACAO_PK] PRIMARY KEY NONCLUSTERED 
(
	[FID_ID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY],
 CONSTRAINT [FIDELIZACAO_UNIQUE_KEY] UNIQUE NONCLUSTERED 
(
	[FID_NUMERO_CARTAO] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[LIMITE_SALDO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[LIMITE_SALDO](
	[CLICOD] [int] NULL,
	[LSDID] [int] IDENTITY(1,1) NOT NULL,
	[LSDVLRLIM] [numeric](15, 2) NULL,
	[LSDVLRPGTEXTANT] [numeric](15, 2) NULL,
	[LSDVLRCOMPRAMES] [numeric](15, 2) NULL,
	[LSDVLRENCREF] [numeric](15, 2) NULL,
	[LSDVLRENCMOR] [numeric](15, 2) NULL,
	[LSDVLRENCMUL] [numeric](15, 2) NULL,
	[LSDVLRAJU] [numeric](15, 2) NULL,
	[LSDVLRTOTEXT] [numeric](15, 2) NULL,
	[LSDVLRPGTMIN] [numeric](15, 2) NULL,
	[LSDVLRBONACU] [numeric](15, 2) NULL,
	[LSDVLRMULT] [numeric](15, 2) NULL,
	[LSDVLRLIMDISP] [numeric](15, 2) NULL,
	[LSDDTVEN] [datetime] NULL,
	[LSDVLRSALEXTANT] [numeric](15, 2) NULL,
	[LSD_ORIGEM_ALTERACAO] [varchar](11) NULL,
	[LSD_DATA_ALTERACAO] [datetime] NULL,
	[LSD_CHAVE_RETAGUARDA] [int] NULL,
	[LSD_VERSAO_RETAGUARDA] [int] NULL,
 CONSTRAINT [PK_LIMITE_SALDO] PRIMARY KEY NONCLUSTERED 
(
	[LSDID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CARTAO_CREDITO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[CARTAO_CREDITO](
	[CTCCOD] [int] IDENTITY(1,1) NOT NULL,
	[CLICOD] [int] NOT NULL,
	[CTCNUMCAR] [varchar](22) NOT NULL,
	[STACOD] [int] NULL,
	[CTCDATVAL] [datetime] NULL,
	[CTCDATCAN] [datetime] NULL,
	[CTC_DEPENDENTE_NOME] [varchar](255) NULL,
	[CTC_ORIGEM_ALTERACAO] [varchar](11) NULL,
	[CTC_DATA_ALTERACAO] [datetime] NULL,
	[CTC_CHAVE_RETAGUARDA] [int] NULL,
	[CTC_VERSAO_RETAGUARDA] [int] NULL,
 CONSTRAINT [PK_CARTAO_CREDITO] PRIMARY KEY NONCLUSTERED 
(
	[CTCCOD] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ITEM_DEVOLUCAO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[ITEM_DEVOLUCAO](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[DEVCOD] [int] NOT NULL,
	[PROCOD] [int] NOT NULL,
	[ITDQTD] [numeric](15, 3) NULL,
	[ITDTIPPRC] [varchar](1) NULL,
	[ITDVLRUNI] [numeric](15, 2) NULL,
	[ITDVLRDCN] [numeric](15, 2) NULL,
	[ITDVLRTOT] [numeric](15, 2) NULL,
	[ITDCOMVEN] [numeric](15, 2) NULL,
	[ITDCOMRED] [numeric](15, 4) NULL,
	[PROCTREST] [varchar](1) NULL,
	[PROCTRSER] [varchar](1) NULL,
	[FUNCOD] [int] NULL,
	[ITDSERPRO] [varchar](20) NULL,
 CONSTRAINT [SYS_C00128553] PRIMARY KEY NONCLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TRANSACAO_PONTOS]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TRANSACAO_PONTOS](
	[TRP_ID] [int] IDENTITY(1,1) NOT NULL,
	[FID_ID] [int] NULL,
	[LOJCOD] [int] NULL,
	[TRNDAT] [datetime] NULL,
	[CXANUM] [varchar](3) NULL,
	[TRNSEQ] [varchar](6) NULL,
	[MVP_ID] [int] NULL,
	[TRP_DATA] [datetime] NULL,
	[TRP_TIPO] [varchar](1) NULL,
	[TRP_VALOR] [numeric](15, 2) NULL,
	[TRP_TRANSACAO_ESTORNO] [int] NULL,
	[TRP_VALOR_ATUAL] [numeric](15, 2) NULL,
 CONSTRAINT [TRANSACAO_PONTOS_PK] PRIMARY KEY NONCLUSTERED 
(
	[TRP_ID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CLIENTE]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[CLIENTE](
	[CLICOD] [int] NOT NULL,
	[CLICAE] [varchar](7) NULL,
	[CLIBAI] [varchar](20) NULL,
	[CLIBAICOB] [varchar](40) NULL,
	[CLICAR] [varchar](50) NULL,
	[CLICEL] [varchar](14) NULL,
	[CLICEP] [varchar](9) NULL,
	[CLICEPCOB] [varchar](10) NULL,
	[CLICID] [varchar](40) NULL,
	[CLICIDCOB] [varchar](20) NULL,
	[FUNCOD] [int] NULL,
	[CLICODINT] [varchar](6) NULL,
	[CLICMP] [varchar](40) NULL,
	[CLICMPCOB] [varchar](15) NULL,
	[CLICPREND] [varchar](1) NULL,
	[CLICPRRDA] [varchar](1) NULL,
	[CLICON] [varchar](40) NULL,
	[CLICPFCGC] [varchar](18) NULL,
	[CLIDTBLO] [datetime] NULL,
	[CLIDTCAD] [datetime] NULL,
	[CLIDTALT] [datetime] NULL,
	[CLIDTNAS] [datetime] NULL,
	[CLIDES] [varchar](100) NULL,
	[CLIDIAFEC] [varchar](2) NULL,
	[CLIDATSUSCOB] [datetime] NULL,
	[CLIEMAIL] [varchar](80) NULL,
	[CLIEND] [varchar](100) NULL,
	[CLIENDCOB] [varchar](100) NULL,
	[CLIEST] [varchar](2) NULL,
	[CLIESTCIV] [varchar](1) NULL,
	[CLIESTCOB] [varchar](2) NULL,
	[CLIFAX] [varchar](14) NULL,
	[CLIFOTO] [ntext] NULL,
	[CLIGERLOG] [varchar](1) NULL,
	[CLIHPAGE] [varchar](60) NULL,
	[CLINAT] [varchar](20) NULL,
	[CLIFAN] [varchar](40) NULL,
	[CLINUM] [varchar](6) NULL,
	[CLINUMCOB] [varchar](6) NULL,
	[CLIOBS] [varchar](255) NULL,
	[CLIOUTRDA] [varchar](40) NULL,
	[CLIPNTREF] [varchar](50) NULL,
	[CLIPRZ] [numeric](15, 2) NULL,
	[CLIRES] [varchar](255) NULL,
	[CLIRGEXP] [varchar](6) NULL,
	[CLIRGCGF] [varchar](20) NULL,
	[CLISAL] [numeric](15, 2) NULL,
	[CLISNH] [varchar](60) NULL,
	[CLISEX] [varchar](1) NULL,
	[CLISITAPR] [varchar](1) NULL,
	[CLITABPRZ] [varchar](4) NULL,
	[CLITEL] [varchar](14) NULL,
	[CLITEL2] [varchar](14) NULL,
	[CLITMPEMP] [varchar](20) NULL,
	[CLITMPRES] [varchar](10) NULL,
	[CLITPBLO] [varchar](3) NULL,
	[CLIPFPJ] [varchar](1) NULL,
	[CLITIPPRC] [int] NULL,
	[CLITIPRES] [varchar](1) NULL,
	[CLIDCN] [numeric](15, 2) NULL,
	[STACOD] [int] NULL,
	[RAMCOD] [int] NULL,
	[LOJCOD] [int] NULL,
	[CLI_ORIGEM_ALTERACAO] [varchar](11) NULL,
	[CLI_CHAVE_RETAGUARDA] [int] NULL,
	[CLI_VERSAO_RETAGUARDA] [int] NULL,
 CONSTRAINT [SYS_C00128748] PRIMARY KEY NONCLUSTERED 
(
	[CLICOD] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CAMPOS_PESQUISA]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[CAMPOS_PESQUISA](
	[CMPCLSATB] [varchar](255) NOT NULL,
	[TBLCOD] [int] NOT NULL,
	[CMPATB] [varchar](255) NULL,
	[CMPWID] [int] NULL,
	[CMPDESCATB] [varchar](60) NULL,
	[CMPORD] [int] NULL,
	[CMPSTA] [char](1) NULL,
	[CMPCLSTIPO] [varchar](50) NULL,
 CONSTRAINT [SYS_C00128507] PRIMARY KEY NONCLUSTERED 
(
	[CMPCLSATB] ASC,
	[TBLCOD] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FINALIZADORA]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[FINALIZADORA](
	[FZDCOD] [int] NOT NULL,
	[FZDDES] [varchar](20) NULL,
	[TPDCOD] [int] NULL,
 CONSTRAINT [SYS_C00128529] PRIMARY KEY NONCLUSTERED 
(
	[FZDCOD] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ACESSO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[ACESSO](
	[ACE_ID] [int] IDENTITY(1,1) NOT NULL,
	[ACEALTERA] [int] NULL,
	[ACEATIVO] [int] NULL,
	[ACEEXCLUI] [int] NULL,
	[ACEINCLUI] [int] NULL,
	[GRPCOD] [int] NULL,
	[MEN_ID] [int] NULL,
 CONSTRAINT [SYS_C00128503] PRIMARY KEY NONCLUSTERED 
(
	[ACE_ID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PARTICIPANTES]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[PARTICIPANTES](
	[FUNCOD] [int] NOT NULL,
	[GRPCOD] [int] NOT NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[LOJA]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[LOJA](
	[LOJCOD] [int] NOT NULL,
	[LOJBAI] [varchar](60) NULL,
	[LOJCEP] [varchar](20) NULL,
	[LOJCGC] [varchar](20) NULL,
	[LOJCGF] [varchar](14) NULL,
	[LOJCID] [varchar](20) NULL,
	[LOJCOM] [varchar](30) NULL,
	[LOJEND] [varchar](60) NULL,
	[LOJEST] [varchar](2) NULL,
	[LOJFANT] [varchar](60) NULL,
	[LOJMETQDR] [numeric](15, 3) NULL,
	[LOJDES] [varchar](60) NULL,
	[LOJTEL] [varchar](20) NULL,
	[LOJTEL2] [varchar](20) NULL,
	[HOLCOD] [int] NULL,
	[LOJIP] [varchar](20) NULL,
	[LOJPORT] [numeric](4, 0) NULL,
 CONSTRAINT [SYS_C00128580] PRIMARY KEY NONCLUSTERED 
(
	[LOJCOD] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ITEM_VENDA]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[ITEM_VENDA](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[PROCOD] [int] NULL,
	[FUNCOD] [int] NULL,
	[ITVBONFAT] [numeric](15, 3) NULL,
	[ITVFUNAUT] [int] NULL,
	[ITVPRCCST] [numeric](15, 2) NULL,
	[ITVPRCVDA] [numeric](15, 3) NULL,
	[ITVPROCOMP] [varchar](1) NULL,
	[ITVQTDVDA] [numeric](15, 3) NULL,
	[ITVSERPRO] [varchar](20) NULL,
	[ITVTIP] [varchar](1) NULL,
	[ITVBONTIP] [varchar](1) NULL,
	[ITVTIPPRC] [varchar](1) NULL,
	[ITVTRBID] [varchar](3) NULL,
	[ITVTRBALQ] [numeric](15, 2) NULL,
	[ITVTRBSIM] [varchar](1) NULL,
	[ITVTRBRED] [numeric](15, 2) NULL,
	[ITVVLRACR] [numeric](15, 2) NULL,
	[ITVVLRDCN] [numeric](15, 2) NULL,
	[ITVVLRTOT] [numeric](15, 2) NULL,
	[ITVVLRUNI] [numeric](15, 3) NULL,
	[LOJCOD] [int] NOT NULL,
	[TRNDAT] [datetime] NOT NULL,
	[CXANUM] [varchar](3) NOT NULL,
	[TRNSEQ] [varchar](6) NOT NULL,
	[ITVFUNCAP] [varchar](6) NULL,
	[ITVFUNPRO] [varchar](6) NULL,
	[ITVCOMCAP] [numeric](15, 2) NULL,
	[ITVCOMPRO] [numeric](15, 2) NULL,
	[ITVCOMVEN] [numeric](15, 2) NULL,
	[PRVNUM] [varchar](9) NULL,
	[ITVCOMRED] [numeric](15, 4) NULL,
	[ITVDCNMGC] [numeric](15, 2) NULL,
	[ITVTXAENT] [varchar](1) NULL,
	[ITVVCCOD] [varchar](6) NULL,
 CONSTRAINT [SYS_C00128573] PRIMARY KEY NONCLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ITEM_RECEBIMENTO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[ITEM_RECEBIMENTO](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[ITRACR] [numeric](15, 2) NULL,
	[ITRCODAUX] [int] NULL,
	[CLICOD] [int] NULL,
	[CTRID] [int] NULL,
	[TPRCOD] [varchar](3) NULL,
	[ITRDAT] [datetime] NULL,
	[ITRDCN] [numeric](15, 2) NULL,
	[ITRATS] [int] NULL,
	[ITRDOC] [varchar](10) NULL,
	[ITRJUR] [numeric](15, 2) NULL,
	[ITRLOJORI] [varchar](4) NULL,
	[PLCRED] [varchar](4) NULL,
	[TPRTIP] [varchar](1) NULL,
	[ITRVLR] [numeric](15, 2) NULL,
	[ITRVLRDEV] [numeric](15, 2) NULL,
	[ITRVLRDOC] [numeric](15, 2) NULL,
	[LOJCOD] [int] NULL,
	[TRNDAT] [datetime] NULL,
	[CXANUM] [varchar](3) NULL,
	[TRNSEQ] [varchar](6) NULL,
	[ITRCODPRP] [varchar](20) NULL,
	[ITRDES] [varchar](6) NULL,
 CONSTRAINT [SYS_C00128563] PRIMARY KEY NONCLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ITEM_PAGAMENTO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[ITEM_PAGAMENTO](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[ITPCODAUX] [int] NULL,
	[ITPOBS] [varchar](120) NULL,
	[ITPVLR] [numeric](15, 2) NULL,
	[LOJCOD] [int] NULL,
	[TRNDAT] [datetime] NULL,
	[CXANUM] [varchar](3) NULL,
	[TRNSEQ] [varchar](6) NULL,
	[TPPCOD] [int] NULL,
	[FUNCOD] [int] NULL,
 CONSTRAINT [SYS_C00128555] PRIMARY KEY NONCLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ITEM_PLANO_PAGAMENTO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[ITEM_PLANO_PAGAMENTO](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[IPPACR] [numeric](15, 3) NULL,
	[FZDCOD] [int] NULL,
	[FUNCOD] [int] NULL,
	[PLACOD] [varchar](2) NULL,
	[IPPDATVEN] [datetime] NULL,
	[IPPEMICHQ] [varchar](15) NULL,
	[FZDESP] [char](1) NULL,
	[IPPJUR] [numeric](15, 2) NULL,
	[IPPLERCMC7] [varchar](1) NULL,
	[FZDCARNUM] [varchar](19) NULL,
	[IPPPAR] [varchar](2) NOT NULL,
	[CTRTAX] [numeric](15, 2) NULL,
	[IPPTXT1] [varchar](15) NULL,
	[IPPTXT2] [varchar](15) NULL,
	[IPPTXT3] [varchar](15) NULL,
	[IPPTXT4] [varchar](15) NULL,
	[IPPPARTOT] [varchar](2) NULL,
	[IPPVLRENT] [numeric](15, 2) NULL,
	[IPPVLRLAN] [numeric](15, 2) NULL,
	[LOJCOD] [int] NULL,
	[TRNDAT] [datetime] NULL,
	[CXANUM] [varchar](3) NULL,
	[TRNSEQ] [varchar](6) NULL,
	[ADMCOD] [int] NULL,
	[SEQFZC] [varchar](3) NULL,
 CONSTRAINT [SYS_C00128558] PRIMARY KEY NONCLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[REDUCAO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[REDUCAO](
	[LOJCOD] [int] NOT NULL,
	[TRNSEQ] [varchar](6) NOT NULL,
	[CXANUM] [varchar](3) NOT NULL,
	[TRNDAT] [datetime] NOT NULL,
	[REDDAT] [datetime] NOT NULL,
	[NUMECF] [char](3) NULL,
	[REDCOO] [char](6) NULL,
	[REDCOOINI] [char](6) NULL,
	[REDCNTRED] [char](6) NULL,
	[REDCNTROP] [char](6) NULL,
	[REDGTINI] [numeric](18, 2) NULL DEFAULT ((0)),
	[REDGTFIM] [numeric](18, 2) NULL DEFAULT ((0)),
	[REDVDABRT] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDTOTCAN] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDTOTDECN] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDVDALIQ] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDVLRBASSUB] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDVLRBASISEN] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDVLRBASNTRB] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDALIQ1] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDVLRBAS1] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDVLRIMP1] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDALIQ2] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDVLRBAS2] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDVLRIMP2] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDALIQ3] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDVLRBAS3] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDVLRIMP3] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDALIQ4] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDVLRBAS4] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDVLRIMP4] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDALIQ5] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDVLRBAS5] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDVLRIMP5] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDALIQ6] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDVLRBAS6] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDVLRIMP6] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDALIQ7] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDVLRBAS7] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDVLRIMP7] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDALIQ8] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDVLRBAS8] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDVLRIMP8] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDALIQ9] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDVLRBAS9] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDVLRIMP9] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDALIQ10] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDVLRBAS10] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDVLRIMP10] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDISSALQ1] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDISSVLRBAS1] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDISSVLRIMP1] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDISSALQ2] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDISSVLRBAS2] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDISSVLRIMP2] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDISSALQ3] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDISSVLRBAS3] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDISSVLRIMP3] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDISSALQ4] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDISSVLRBAS4] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDISSVLRIMP4] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDVLRBASSER] [numeric](15, 2) NULL DEFAULT ((0)),
	[REDSEREQP] [varchar](20) NULL,
	[REDCOOCUPINI] [char](6) NULL,
	[REDCOOCUPFIM] [char](6) NULL,
	[REDTRF] [char](1) NULL,
	[REDMFDPERLIV] [numeric](15, 2) NULL DEFAULT ((0)),
 CONSTRAINT [SYS_C00128607] PRIMARY KEY NONCLUSTERED 
(
	[LOJCOD] ASC,
	[TRNSEQ] ASC,
	[CXANUM] ASC,
	[TRNDAT] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CONSUMIDOR_MOVIMENTACAO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[CONSUMIDOR_MOVIMENTACAO](
	[ID] [int] NOT NULL,
	[TRNSEQ] [varchar](6) NULL,
	[CXANUM] [varchar](3) NULL,
	[TRNDAT] [datetime] NULL,
	[CSMCPF] [char](14) NULL,
	[LOJCOD] [int] NULL,
 CONSTRAINT [ID] PRIMARY KEY NONCLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[IMPOSTOS_FEDERAIS_PRODUTO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[IMPOSTOS_FEDERAIS_PRODUTO](
	[IMPFPID] [int] IDENTITY(1,1) NOT NULL,
	[IMPFEDID] [int] NOT NULL,
	[PROID] [int] NOT NULL,
 CONSTRAINT [PK_IMPOSTOS_FEDERAIS_PRODUTO] PRIMARY KEY NONCLUSTERED 
(
	[IMPFPID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TROCO_PREMIADO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TROCO_PREMIADO](
	[TPMNUM] [int] NOT NULL,
	[TPMPROP] [int] NOT NULL,
	[TPMSTA] [varchar](1) NULL,
	[TPMLOJCOD] [int] NULL,
	[TPMTRNDAT] [datetime] NULL,
	[TPMCXANUM] [varchar](3) NULL,
	[TPMTRNSEQ] [varchar](6) NULL,
	[TPMITRVLR] [numeric](15, 2) NULL,
	[TPMITRVLRDEV] [numeric](15, 2) NULL,
	[TPMITRVLRDOC] [numeric](15, 2) NULL,
	[TPMCLICOD] [int] NULL,
	[TPMFZDCOD] [int] NULL,
	[TPRNUMREM] [int] NULL,
	[TPMNUMSER] [int] NULL,
	[TPMTRNDATHOR] [datetime] NULL,
	[TPMSEQ] [int] NULL,
	[TPMCODBAR] [varchar](44) NULL,
	[TPTNUM] [int] NULL,
 CONSTRAINT [PK_TROCO_SORTE] PRIMARY KEY NONCLUSTERED 
(
	[TPMNUM] ASC,
	[TPMPROP] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PRECO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[PRECO](
	[LOJCOD] [int] NOT NULL,
	[PROCOD] [int] NOT NULL,
	[PRCVDAVAR] [numeric](15, 2) NULL,
	[PRCOFEVAR] [numeric](15, 2) NULL,
	[PRCMRG1] [numeric](15, 2) NULL,
	[PRCVDA2] [numeric](15, 2) NULL,
	[PRCOFE2] [numeric](15, 2) NULL,
	[PRCMRG2] [numeric](15, 2) NULL,
	[PRCQTDMINPRC2] [numeric](15, 3) NULL,
	[PRCVDA3] [numeric](15, 2) NULL,
	[PRCOFE3] [numeric](15, 2) NULL,
	[PRCMRG3] [numeric](15, 2) NULL,
	[PRCQTDMINPRC3] [numeric](15, 3) NULL,
	[PRCCST] [numeric](15, 2) NULL,
	[PRCDTULTRE] [datetime] NULL,
	[PRCDTULTRE2] [datetime] NULL,
	[PRCDTULTRE3] [datetime] NULL,
	[PRCPRECO1] [numeric](15, 2) NULL,
	[PRCPRECO2] [numeric](15, 2) NULL,
	[PRCPRECO3] [numeric](15, 2) NULL,
	[PRCDCNMAX] [numeric](15, 2) NULL,
	[PRCPERDCN] [varchar](1) NULL,
	[PRCID] [int] IDENTITY(1,1) NOT NULL,
 CONSTRAINT [FU_PRECO_LOJA_PRODUTO] UNIQUE NONCLUSTERED 
(
	[PROCOD] ASC,
	[LOJCOD] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PREFINALIZACAO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[PREFINALIZACAO](
	[PRVNUM] [int] NULL,
	[LOJCOD] [int] NULL,
	[FZDCOD] [int] NULL,
	[PFZSEQ] [int] NULL,
	[PFZTROCO] [numeric](15, 2) NULL,
	[PFZVLR] [numeric](15, 2) NULL,
	[FZDESP] [char](1) NULL,
	[ID] [int] NOT NULL,
 CONSTRAINT [ID_PREFINALIZACAO] PRIMARY KEY NONCLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PREVENDA]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[PREVENDA](
	[PRVNUM] [int] NOT NULL,
	[LOJCOD] [int] NULL,
	[TRNDAT] [datetime] NULL,
	[TRNSEQ] [varchar](6) NULL,
	[CXANUM] [varchar](3) NULL,
	[PRVSTA] [char](1) NULL,
	[PRVDATEMI] [datetime] NULL,
	[PRVVLR] [numeric](15, 2) NULL,
	[CLICOD] [int] NULL,
	[PRVCLIDES] [varchar](100) NULL,
	[PRVCLICPFCGC] [varchar](18) NULL,
	[PRVCLIDATNAS] [datetime] NULL,
	[PRVCLISEX] [char](1) NULL,
	[PRVCLIRGCGF] [varchar](20) NULL,
	[PRVCLIEND] [varchar](100) NULL,
	[PRVCLINUM] [varchar](6) NULL,
	[PRVCLICMP] [varchar](40) NULL,
	[PRVCLIBAI] [varchar](20) NULL,
	[PRVCLICID] [varchar](40) NULL,
	[PRVCLIEST] [varchar](2) NULL,
	[PRVCLIPAIS] [varchar](40) NULL,
 CONSTRAINT [PK_PREVENDA] PRIMARY KEY NONCLUSTERED 
(
	[PRVNUM] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MOVIMENTO_PREMIO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[MOVIMENTO_PREMIO](
	[MVP_ID] [int] IDENTITY(1,1) NOT NULL,
	[LOJCOD] [int] NULL,
	[PRE_ID] [int] NULL,
	[MVP_QUANTIDADE] [int] NOT NULL,
	[MVP_TIPO] [varchar](1) NOT NULL,
	[MVP_DATA] [timestamp] NOT NULL,
 CONSTRAINT [MOVIMENTO_PREMIO_PK] PRIMARY KEY NONCLUSTERED 
(
	[MVP_ID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[LOCAL]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[LOCAL](
	[LOCCOD] [int] NOT NULL,
	[LOJCOD] [int] NOT NULL,
	[LOCDESC] [varchar](60) NULL,
 CONSTRAINT [SYS_C00128578] PRIMARY KEY NONCLUSTERED 
(
	[LOCCOD] ASC,
	[LOJCOD] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ITEM_PREVENDA]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[ITEM_PREVENDA](
	[PRVNUM] [int] NOT NULL,
	[PROCOD] [varchar](14) NOT NULL,
	[IPVQTD] [numeric](15, 2) NULL,
	[IPVVLRUNI] [numeric](15, 2) NULL,
	[IPVDCN] [numeric](15, 2) NULL,
	[IPVDCNTIP] [char](1) NULL,
	[IPVVLRTOT] [numeric](15, 2) NULL,
	[IPVPRODES] [varchar](45) NULL,
	[IPVPRODESRDZ] [varchar](20) NULL,
	[IPVTRBID] [char](3) NULL,
 CONSTRAINT [PK_ITEM_PREVENDA] PRIMARY KEY NONCLUSTERED 
(
	[PRVNUM] ASC,
	[PROCOD] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FUNCIONARIO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[FUNCIONARIO](
	[FUNCOD] [int] NOT NULL,
	[FUNAPE] [varchar](50) NULL,
	[FUNBAI] [varchar](20) NULL,
	[FUNCAR] [varchar](15) NULL,
	[FUNCEL] [varchar](10) NULL,
	[FUNCEP] [varchar](12) NULL,
	[FUNCID] [varchar](50) NULL,
	[FUNCOMP] [varchar](60) NULL,
	[FUNCPF] [varchar](20) NULL,
	[FUNDTNAS] [varchar](10) NULL,
	[FUNEMA] [varchar](60) NULL,
	[FUNEND] [varchar](50) NULL,
	[FUNRAM] [varchar](10) NULL,
	[FUNTEL] [varchar](10) NULL,
	[FUNTEL2] [varchar](10) NULL,
	[FUNUF] [varchar](2) NULL,
	[LOJCOD] [int] NULL,
	[FUNDES] [varchar](30) NULL,
	[FUNCOM] [numeric](15, 2) NULL,
	[FUNCOM2] [numeric](15, 2) NULL,
	[FUNCOM3] [numeric](15, 2) NULL,
 CONSTRAINT [SYS_C00128533] PRIMARY KEY NONCLUSTERED 
(
	[FUNCOD] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FILA_SINCRONIZACAO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[FILA_SINCRONIZACAO](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[LOJA] [int] NOT NULL,
	[IDENTIFICADOR] [varchar](20) NOT NULL,
	[DADO] [varchar](500) NOT NULL,
	[DATA_ENTRADA] [datetime] NOT NULL,
	[DATA_ENVIO] [datetime] NULL,
	[DATA_RETORNO] [datetime] NULL,
	[OBSERVACAO] [varchar](255) NULL,
	[STATUS] [varchar](255) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[URL]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[URL](
	[URL_ID] [int] NOT NULL,
	[URLENDE] [varchar](60) NULL,
	[MEN_ID] [int] NULL,
 CONSTRAINT [SYS_C00128671] PRIMARY KEY NONCLUSTERED 
(
	[URL_ID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SP_AUTORIZADOR_CARTAO_CREDITO]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE PROCEDURE [dbo].[SP_AUTORIZADOR_CARTAO_CREDITO]
(
  @CodigoCliente 			INT,
  @NumeroCartao 			VARCHAR(22),
  @StatusCartao 			INT,
  @DataValidade 			DATETIME,
  @DataCancelamento 		DATETIME,
  @NomeDependente 		VARCHAR(100),
  @ChaveRetaguarda 		INT,
  @VersaoRetaguarda 		INT
)
AS

BEGIN TRY
  
DECLARE cr_cartao cursor for SELECT * FROM CARTAO_CREDITO
         WHERE CTCNUMCAR = @NumeroCartao  for UPDATE;

	OPEN cr_cartao;
	FETCH NEXT FROM cr_cartao;

	if (CAST(@CodigoCliente AS VARCHAR) is NULL OR CAST(@CodigoCliente AS VARCHAR) = '''') 
		RAISERROR (''CodigoCliente está nulo ou em braco'', 16, 1);

	if (CAST(@NumeroCartao AS VARCHAR) is NULL OR CAST(@NumeroCartao AS VARCHAR) = '''') 
		RAISERROR (''NumeroCartao está nulo ou em braco'', 16, 1);

	if (CAST(@StatusCartao AS VARCHAR) is NULL OR CAST(@StatusCartao AS VARCHAR) = '''') 
		RAISERROR (''StatusCartao está nulo ou em braco'', 16, 1);

	if (CAST(@NomeDependente AS VARCHAR) is NULL OR CAST(@NomeDependente AS VARCHAR) = '''') 
		RAISERROR (''NomeDependente está nulo ou em braco'', 16, 1);


	if @@FETCH_STATUS = 0  
		UPDATE CARTAO_CREDITO SET
				CLICOD = @CodigoCliente,
				STACOD = @StatusCartao,
				CTCDATVAL = @DataValidade,
				CTCDATCAN = @DataCancelamento,
				CTC_DEPENDENTE_NOME = @NomeDependente,
				CTC_CHAVE_RETAGUARDA = @ChaveRetaguarda,
				CTC_VERSAO_RETAGUARDA = @VersaoRetaguarda,
				CTC_ORIGEM_ALTERACAO = ''ERP'',
				CTC_DATA_ALTERACAO = getdate()
		  WHERE CURRENT OF cr_cartao;
	ELSE

	  INSERT INTO CARTAO_CREDITO(CLICOD, CTCNUMCAR, STACOD, CTCDATVAL, CTCDATCAN, CTC_DEPENDENTE_NOME,CTC_CHAVE_RETAGUARDA,CTC_VERSAO_RETAGUARDA, CTC_ORIGEM_ALTERACAO, CTC_DATA_ALTERACAO)
		  values(@CodigoCliente, @NumeroCartao, @StatusCartao,@DataValidade,@DataCancelamento,@NomeDependente,@ChaveRetaguarda,@VersaoRetaguarda, ''ERP'', getdate());

  close cr_cartao;
  DEALLOCATE cr_cartao;

END TRY

BEGIN CATCH
  
    close cr_cartao;
    DEALLOCATE cr_cartao;

    SELECT
        (CAST(ERROR_NUMBER()AS NVARCHAR(20) ) + '' - '' + ERROR_MESSAGE() ) AS ErrorMessage;
        
END CATCH;


' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SP_CARTAO_CREDITO_ATUALIZACAO]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'


CREATE PROCEDURE [dbo].[SP_CARTAO_CREDITO_ATUALIZACAO]
(
	@CodigoCliente   	INT,
	@NumeroCartao 		VARCHAR(22),
	@StatusCartao 		INT,
	@ChaveRetaguarda 	INT,
	@VersaoRetaguarda   INT
)
AS

BEGIN TRY

      if (CAST(@CodigoCliente AS VARCHAR) is NULL OR CAST(@CodigoCliente AS VARCHAR) = '''') 
			RAISERROR (''CodigoCliente está nulo ou em braco'', 16, 1);     
			
      if (CAST(@NumeroCartao AS VARCHAR) is NULL OR CAST(@NumeroCartao AS VARCHAR) = '''')
			RAISERROR (''NumeroCartao está nulo ou em braco'', 16, 1);

	  if (CAST(@StatusCartao AS VARCHAR) is NULL OR CAST(@StatusCartao AS VARCHAR) = '''') 
			RAISERROR (''StatusCartao está nulo ou em braco'', 16, 1);

	  UPDATE CARTAO_CREDITO SET
		  CLICOD = @CodigoCliente,
		  STACOD = @StatusCartao,
		  CTC_CHAVE_RETAGUARDA = @ChaveRetaguarda,
		  CTC_VERSAO_RETAGUARDA = @VersaoRetaguarda,
		  CTC_ORIGEM_ALTERACAO = ''ERP'',
		  CTC_DATA_ALTERACAO = getdate()
		  WHERE CTCNUMCAR = @NumeroCartao;

END TRY

BEGIN CATCH
    SELECT
        (CAST(ERROR_NUMBER()AS NVARCHAR(20) ) + '' - '' + ERROR_MESSAGE() ) AS ErrorMessage;
END CATCH;



' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_cep]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE PROCEDURE [dbo].[sp_cep]  	
/*Declara variaveis de CEP*/    

@cep varchar(20),  	
@complemento varchar(100), 	
@logradouro varchar(100), 	
@bairro varchar(80), 	
@estado varchar(2), 	
@municipio varchar(80)  

AS BEGIN	 
  IF	(SELECT COUNT(*) 
    FROM CEP WHERE CEPCOD = @cep ) > 0  	
  BEGIN 		
	update CEP set
	CEPCOD		 = @cep,  			
	CEPCOMP		 = @complemento, 
	CEPLOG       = @logradouro, 		
	CEPBAIR		 = @bairro,	 				
	CEPEST		 = @estado, 				
	CEPMUN		 = @municipio   			
	where	CEPCOD   = @cep 	
	END  ELSE     
 BEGIN 	
	INSERT INTO CEP(CEPCOD, CEPCOMP, CEPLOG, CEPBAIR, CEPEST, CEPMUN) 
	values( @cep, @complemento, @logradouro, @bairro, @estado, @municipio)  	

	END
END;   

' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_cliente]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE PROCEDURE [dbo].[sp_cliente]  	/*Declara variaveis de cliente*/     
	 @codigo bigint,  	
	 @loja int, 	
	 @status int, 	
	 @ramo int,        
	 @descricao varchar(100), 	
	 @endereco varchar(100),     
	 @cpfcgc varchar(18),     
	 @bairro varchar(20),     
	 @telefone varchar(14),     
	 @cep varchar(9),     
	 @cidade varchar(40),    
	 @numero varchar(6),     
	 @complemento varchar(40),     
	 @estado varchar(2),     
	 @tabelaPrazo varchar(4),   
	 @prazo numeric(15,2),     
	 @nomeFantasia varchar(40),     
	 @rgcgf varchar(20),     
	 @dataCadastro datetime,     
	 @dataNascimento datetime,     
	 @dataBloqueio datetime,     
	 @tipoPessoa varchar(1),     
	 @telefone2 varchar(14),     
	 @fax varchar(14),     
	 @contato varchar(40), 
	 @enderecoCobranca varchar(100),     
	 @bairroCobranca varchar(40),     
	 @cepCobranca varchar(9),    
	 @cidadeCobranca varchar(20),     
	 @numeroCobranca varchar(6),     
	 @complementoCobranca varchar(15),     
	 @estadoCobranca varchar(2),     
	 @valorDesconto numeric(15,2),     
	 @observacao varchar(150),    
	 @restricoes varchar(150),     
	 @dataDeAlteracao datetime,     
	 @email varchar(80),     
	 @atividadeEconomica varchar(7),    
	 @sexo varchar(1),     
	 @tipoResidencia varchar(1),     
	 @tempoResidencia varchar(10),     
	 @cargo varchar(50),     
	 @pontoDeReferencia varchar(50),     
	 @comprovanteEndereco varchar(1),     
	 @comprovanteRenda varchar(1),     
	 @estadoCivil varchar(1),     
	 @situacaoAprovacao varchar(1),     
	 @diaFechamento varchar(2),     
	 @naturalidade varchar(20), 	
	 @rgExpedicao varchar(6),     
	 @tipoPreco int,     
	 @codigoInterno varchar(6),     
	 @salario numeric(15,2),    
	 @outraRenda varchar(40),     
	 @tempoEmpresa varchar(20)    
 
 AS BEGIN 	 
	 IF	(SELECT COUNT(*) FROM cliente WHERE clicod = @codigo ) > 0  	
		 BEGIN 		
			update CLIENTE set	CLICOD		 = @codigo,  						
				 LOJCOD		 = @loja, 							
				 STACOD		 = @status, 							
				 RAMCOD		 = @ramo, 							
				 CLIDES		 = @descricao, 							
				 CLIEND		 = @endereco, 							
				 CLICPFCGC	 = @cpfcgc, 							
				 CLIBAI		 = @bairro, 							
				 CLITEL		 = @telefone, 							
				 CLICEP		 = @cep, 							
				 CLICID		 = @cidade, 							
				 CLINUM		 = @numero, 							
				 CLICMP		 = @complemento, 							
				 CLIEST		 = @estado, 							
				 CLITABPRZ    = @tabelaPrazo, 							
				 CLIPRZ		 = @prazo, 							
				 CLIFAN		 = @nomeFantasia, 							
				 CLIRGCGF	 = @rgcgf, 							
				 CLIDTCAD	 = @dataCadastro, 							
				 CLIDTNAS	 = @dataNascimento, 							
				 CLIDTBLO	 = @dataBloqueio, 							
				 CLIPFPJ		 = @tipoPessoa, 							
				 CLITEL2		 = @telefone2, 							
				 CLIFAX		 = @fax, 							
				 CLICON	     = @contato, 							
				 CLIENDCOB	 = @enderecoCobranca, 							
				 CLIBAICOB	 = @bairroCobranca, 							
				 CLICEPCOB	 = @cepCobranca, 							
				 CLICIDCOB	 = @cidadeCobranca, 							
				 CLINUMCOB	 = @numeroCobranca, 							
				 CLICMPCOB	 = @complementoCobranca, 							
				 CLIESTCOB	 = @estadoCobranca, 							
				 CLIDCN		 = @valorDesconto, 							
				 CLIOBS		 = @observacao, 							
				 CLIRES		 = @restricoes, 							
				 CLIDTALT	 = @dataDeAlteracao, 							
				 CLIEMAIL	 = @email, 							
				 CLICAE		 = @atividadeEconomica, 							
				 CLISEX 		 = @sexo, 							
				 CLITIPRES	 = @tipoResidencia, 							
				 CLITMPRES	 = @tempoResidencia, 							
				 CLICAR	     = @cargo, 							
				 CLIPNTREF	 = @pontoDeReferencia, 							
				 CLICPREND	 = @comprovanteEndereco, 							
				 CLICPRRDA	 = @comprovanteRenda, 							
				 CLIESTCIV	 = @estadoCivil, 							
				 CLISITAPR	 = @situacaoAprovacao, 							
				 CLIDIAFEC	 = @diaFechamento, 							
				 CLINAT	     = @naturalidade, 							
				 CLIRGEXP	 = @rgExpedicao, 							
				 CLITIPPRC	 = @tipoPreco, 							
				 CLICODINT	 = @codigoInterno, 							
				 CLISAL	     = @salario, 							
				 CLIOUTRDA	 = @outraRenda, 							
				 CLITMPEMP	 = @tempoEmpresa 					
			where	CLICOD  	 = @codigo END  ELSE   
			BEGIN 	
				 INSERT INTO CLIENTE(CLICOD, LOJCOD, STACOD, RAMCOD, CLIDES, CLIEND, CLICPFCGC, CLIBAI, CLITEL, 						
				 CLICEP, CLICID, CLINUM, CLICMP, CLIEST, CLITABPRZ, CLIPRZ, CLIFAN, 						
				 CLIRGCGF, CLIDTCAD, CLIDTNAS, CLIDTBLO, CLIPFPJ, CLITEL2, CLIFAX, 						
				 CLICON, CLIENDCOB, CLIBAICOB, CLICEPCOB, CLICIDCOB, CLINUMCOB, CLICMPCOB, 						
				 CLIESTCOB, CLIDCN, CLIOBS, CLIRES, CLIDTALT, CLIEMAIL, 						
				 CLICAE, CLISEX, CLITIPRES, CLITMPRES, CLICAR, CLIPNTREF, CLICPREND, CLICPRRDA, 						
				 CLIESTCIV, CLISITAPR, CLIDIAFEC, CLINAT, CLIRGEXP, CLITIPPRC,  						
				 CLICODINT, CLISAL, CLIOUTRDA, CLITMPEMP ) 				  				
				 values( @codigo, @loja, @status, @ramo, @descricao, @endereco, @cpfcgc, @bairro, 						
				 @telefone, @cep, @cidade, @numero, @complemento, @estado, @tabelaPrazo, 						
				 @prazo, @nomeFantasia, @rgcgf, @dataCadastro, @dataNascimento, @dataBloqueio, 						
				 @tipoPessoa, @telefone2, @fax, @contato, @enderecoCobranca, @bairroCobranca, 						
				 @cepCobranca, @cidadeCobranca, @numeroCobranca, @complementoCobranca, @estadoCobranca, 						
				 @valorDesconto, @observacao, @restricoes, @dataDeAlteracao, 						
				 @email, @atividadeEconomica, @sexo, @tipoResidencia, @tempoResidencia, @cargo, @pontoDeReferencia, 						
				 @comprovanteEndereco, @comprovanteRenda, @estadoCivil, @situacaoAprovacao, @diaFechamento, @naturalidade, 						
				 @rgExpedicao, @tipoPreco, @codigoInterno, 						
				 @salario, @outraRenda, @tempoEmpresa  )  	
			END
	END;
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SP_IMPORTACAO_CLIENTE]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'--  create procedure sp importacao cliente
CREATE PROCEDURE [dbo].[SP_IMPORTACAO_CLIENTE]
(
  @V_CLICOD     VARCHAR,
  @V_CLIDES      VARCHAR,
  @V_CLICPFCGC   CHAR,
  @V_CLIEND    VARCHAR,
  @V_CLIBAI     VARCHAR,
  @V_CLICID     VARCHAR,
  @V_CLIEST     CHAR,
  @V_CLICEP     CHAR,
  @V_CLINUM     VARCHAR,
  @V_CLICMP     VARCHAR,
  @V_CLITEL     VARCHAR,
  @V_STACOD     CHAR,
  @V_CLITABPRZ   CHAR,
  @V_CLIPRZ     numeric(15,2),
  @V_CLIFAN     VARCHAR,
  @V_CLIRGCGF    VARCHAR,
  @V_CLIDTCAD    datetime,
  @V_CLIDTNAS    datetime,
  @V_CLIDTBLO    datetime,
  @V_CLIPFPJ    CHAR,
  @V_CLITEL2    VARCHAR,
  @V_CLIFAX     VARCHAR,
  @V_CLICON     VARCHAR,
  @V_CLIENDCOB   VARCHAR,
  @V_CLIBAICOB   VARCHAR,
  @V_CLICEPCOB   CHAR,
  @V_CLICIDCOB   VARCHAR,
  @V_CLIESTCOB   CHAR,
  @V_CLINUMCOB   VARCHAR,
  @V_CLICMPCOB   VARCHAR,
  @V_CLIDCN     numeric (15,2),
  @V_CLIOBS     VARCHAR,
  @V_CLIRES     VARCHAR,
  @V_CLIEMAIL    VARCHAR,
  @V_CLIDTALT    datetime,
  @V_CLICAE     VARCHAR,
  @V_CLISEX     CHAR,
  @V_CLITIPRES   CHAR,
  @V_CLITMPRES   VARCHAR,
  @V_CLICAR     VARCHAR,
  @V_CLIPNTREF   VARCHAR,
  @V_CLICPREND    CHAR,
  @V_CLICPRRDA    CHAR,
  @V_CLISAL       numeric(15,2),
  @V_CLIOUTRDA    VARCHAR,
  @V_CLIESTCIV    CHAR,
  @V_CLISITAPR    CHAR,
  @V_CLIDIAFEC    CHAR,
  @V_CLINAT       VARCHAR,
  @V_CLIRGEXP     CHAR,
  @V_CLITIPPRC    CHAR,
  @V_RAMCOD       CHAR,
  @V_FUNCOD       CHAR,
  @V_CLICODINT    VARCHAR
 )
AS
 
begin
  
   IF	(SELECT COUNT(*) FROM cliente WHERE CLICOD = @V_CLICOD ) > 0 
   
    UPDATE CLIENTE SET CLICOD     = @V_CLICOD,
                       CLIDES     = @V_CLIDES,
                       CLICPFCGC  = @V_CLICPFCGC,
                       CLIEND     = @V_CLIEND,
                       CLIBAI     = @V_CLIBAI,
                       CLICID     = @V_CLICID,
                       CLIEST     = @V_CLIEST,
                       CLICEP     = @V_CLICEP,
                       CLINUM     = @V_CLINUM,
                       CLICMP     = @V_CLICMP,
                       CLITEL     = @V_CLITEL,
                       STACOD     = @V_STACOD,
                       CLITABPRZ  = @V_CLITABPRZ,
                       CLIPRZ     = @V_CLIPRZ,
                       CLIFAN     = @V_CLIFAN,
                       CLIRGCGF   = @V_CLIRGCGF,
                       CLIDTCAD   = @V_CLIDTCAD,
                       CLIDTNAS   = @V_CLIDTNAS,
                       CLIDTBLO   = @V_CLIDTBLO,
                       CLIPFPJ    = @V_CLIPFPJ,
                       CLITEL2    = @V_CLITEL2,
                       CLIFAX     = @V_CLIFAX,
                       CLICON     = @V_CLICON,
                       CLIENDCOB  = @V_CLIENDCOB,
                       CLIBAICOB  = @V_CLIBAICOB,
                       CLICEPCOB  = @V_CLICEPCOB,
                       CLICIDCOB  = @V_CLICIDCOB,
                       CLIESTCOB  = @V_CLIESTCOB,
                       CLIDCN     = @V_CLIDCN,
                       CLIOBS     = @V_CLIOBS,
                       CLIRES     = @V_CLIRES,
                       CLIEMAIL   = @V_CLIEMAIL,
                       CLIDTALT   = @V_CLIDTALT,
                       CLICAE     = @V_CLICAE,
                       CLISEX     = @V_CLISEX,
                       CLITIPRES  = @V_CLITIPRES,
                       CLITMPRES  = @V_CLITMPRES,
                       CLICAR     = @V_CLICAR,
                       CLIPNTREF  = @V_CLIPNTREF,
                       CLICPREND  = @V_CLICPREND,
                       CLICPRRDA  = @V_CLICPRRDA,
                       CLISAL     = @V_CLISAL,
                       CLIOUTRDA  = @V_CLIOUTRDA,
                       CLIESTCIV  = @V_CLIESTCIV,
                       CLISITAPR     = @V_CLISITAPR,
                       CLIDIAFEC     = @V_CLIDIAFEC,
                       CLINAT        = @V_CLINAT,
                       CLIRGEXP      = @V_CLIRGEXP,
                       CLITIPPRC  = @V_CLITIPPRC,
                       RAMCOD        = @V_RAMCOD,
                       FUNCOD        = @V_FUNCOD,
                       CLICODINT     = @V_CLICODINT
                 WHERE CLICOD        = @V_CLICOD;
  ELSE
    INSERT INTO CLIENTE(CLICOD,CLIDES,
                        CLICPFCGC,CLIEND,
                        CLIBAI,CLICID,
                        CLIEST,CLICEP,
                        CLINUM,CLICMP,
                        CLITEL,
                        STACOD,
                        CLITABPRZ,CLIPRZ,
                        CLIFAN,CLIRGCGF,
                        CLIDTCAD,CLIDTNAS,
                        CLIDTBLO,CLIPFPJ,
                        CLITEL2,CLIFAX,
                        CLICON,CLIENDCOB,
                        CLIBAICOB,CLICEPCOB,
                        CLICIDCOB,CLIESTCOB,
                        CLINUMCOB,CLICMPCOB,
                        CLIDCN,CLIOBS,
                        CLIRES,
                        CLIEMAIL,CLIDTALT,
                        CLICAE,CLISEX,
                        CLITIPRES,CLITMPRES,
                        CLICAR,CLIPNTREF,
                        CLICPREND,CLICPRRDA,
                        CLISAL,
                        CLIOUTRDA,CLIESTCIV,
                        CLISITAPR,
                        CLIDIAFEC,
                        CLINAT,CLIRGEXP,
                        CLITIPPRC,RAMCOD,
                        FUNCOD,CLICODINT)
                 values(@V_CLICOD,@V_CLIDES,
                        @V_CLICPFCGC,@V_CLIEND,
                        @V_CLIBAI,@V_CLICID,
                        @V_CLIEST,@V_CLICEP,
                        @V_CLINUM,@V_CLICMP,
                        @V_CLITEL,
                        @V_STACOD,
                        @V_CLITABPRZ,@V_CLIPRZ,
                        @V_CLIFAN,@V_CLIRGCGF,
                        @V_CLIDTCAD,@V_CLIDTNAS,
                        @V_CLIDTBLO,@V_CLIPFPJ,
                        @V_CLITEL2,@V_CLIFAX,
                        @V_CLICON,@V_CLIENDCOB,
                        @V_CLIBAICOB,@V_CLICEPCOB,
                        @V_CLICIDCOB,@V_CLIESTCOB,
                        @V_CLINUMCOB,@V_CLICMPCOB,
                        @V_CLIDCN,@V_CLIOBS,
                        @V_CLIRES,
                        @V_CLIEMAIL,@V_CLIDTALT,
                        @V_CLICAE,@V_CLISEX,
                        @V_CLITIPRES,@V_CLITMPRES,
                        @V_CLICAR,@V_CLIPNTREF,
                        @V_CLICPREND,@V_CLICPRRDA,
                        @V_CLISAL,
                        @V_CLIOUTRDA,@V_CLIESTCIV,
                        @V_CLISITAPR,
                        @V_CLIDIAFEC,
                        @V_CLINAT,@V_CLIRGEXP,
                        @V_CLITIPPRC,@V_RAMCOD,
                        @V_FUNCOD,@V_CLICODINT);
  
END;

' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SP_CLIENTE_CARTAO_ATUALIZACAO]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

CREATE PROCEDURE [dbo].[SP_CLIENTE_CARTAO_ATUALIZACAO]
(
  @CodigoCliente 		INT,
  @CodigoStatus 		INT,
  @ChaveRetaguarda 		INT,
  @VersaoRetaguarda 	INT
)

AS

BEGIN TRY

	if (CAST(@CodigoCliente AS VARCHAR) is NULL OR CAST(@CodigoCliente AS VARCHAR) = '''') 
		RAISERROR (''CodigoCliente está nulo ou em braco'', 16, 1); 

	 if (CAST(@CodigoStatus AS VARCHAR) is NULL OR CAST(@CodigoStatus AS VARCHAR) = '''') 

		 UPDATE CLIENTE SET
				CLI_CHAVE_RETAGUARDA = @ChaveRetaguarda,
				CLI_VERSAO_RETAGUARDA = @VersaoRetaguarda ,
				CLI_ORIGEM_ALTERACAO = ''ERP'',
				CLIDTALT = getdate()
		  WHERE CLICOD  = @CodigoCliente;

	 else

		 UPDATE CLIENTE SET
				STACOD = @CodigoStatus,
				CLI_CHAVE_RETAGUARDA = @ChaveRetaguarda,
				CLI_VERSAO_RETAGUARDA = @VersaoRetaguarda ,
				CLI_ORIGEM_ALTERACAO = ''ERP'',
				CLIDTALT = getdate()
		  WHERE CLICOD  = @CodigoCliente;
END TRY

BEGIN CATCH
    SELECT
        (CAST(ERROR_NUMBER()AS NVARCHAR(20) ) + '' - '' + ERROR_MESSAGE() ) AS ErrorMessage;
END CATCH;


' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SP_AUTORIZADOR_CLIENTE_CARTAO]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE PROCEDURE [dbo].[SP_AUTORIZADOR_CLIENTE_CARTAO]
(
  @CodigoCliente 			INT,
  @Cargo  					VARCHAR(50),
  @Celular  				VARCHAR(14),
  @CEP  						VARCHAR(9),
  @Cidade 					VARCHAR(40),
  @CPFCNPJ  				VARCHAR(18),
  @Nascimento  			DATETIME,
  @Nome 						VARCHAR(100),
  @DiaVencimento  		VARCHAR(2),
  @Email 					VARCHAR(80),
  @Endereco  				VARCHAR(100),
  @UF  						VARCHAR(2),
  @EstadoCivil  			VARCHAR(1),
  @Fax 						VARCHAR(14),
  @Naturalidade   		VARCHAR(20),
  @NumeroEndereco 		VARCHAR(6),
  @Observacao     		VARCHAR(150),
  @Restricoes     		VARCHAR(150),
  @OrgaoExpedidorRG  	VARCHAR(6),
  @InscricaoEstadualRG  VARCHAR(20),
  @Salario  				NUMERIC(15,2),
  @SexoCliente 			VARCHAR(1),
  @Telefone1 				VARCHAR(14),
  @Telefone2 				VARCHAR(14),
  @TipoPessoa 				VARCHAR(1),
  @CodigoStatus 			INT,
  @CodigoLoja 				INT,
  @ChaveRetaguarda 		INT,
  @VersaoRetaguarda 		INT
)

AS

BEGIN TRY
  
DECLARE cr_cliente_cartao cursor for SELECT * FROM CLIENTE
         WHERE CLICOD = @CodigoCliente  for UPDATE;

	OPEN cr_cliente_cartao;
	FETCH NEXT FROM cr_cliente_cartao;
  
  
	if (CAST(@CodigoCliente AS VARCHAR) is NULL OR CAST(@CodigoCliente AS VARCHAR) = '''') 
		 RAISERROR (''CodigoCliente está nulo ou em braco'', 16, 1);

	if (CAST(@CPFCNPJ AS VARCHAR) is NULL OR CAST(@CPFCNPJ AS VARCHAR) = '''') 
		 RAISERROR (''CPFCNPJ está nulo ou em braco'', 16, 1);

	if (@Nome is NULL OR @Nome = '''') 
		 RAISERROR (''Nome está nulo ou em braco'', 16, 1);

	if (@TipoPessoa is NULL OR @TipoPessoa = '''') 
		 RAISERROR (''TipoPessoa está nulo ou em braco'', 16, 1);

	if (CAST(@CodigoStatus AS VARCHAR) is NULL OR CAST(@CodigoStatus AS VARCHAR) = '''') 
		 RAISERROR (''CodigoStatus está nulo ou em braco'', 16, 1);

	if (CAST(@CodigoLoja AS VARCHAR) is NULL OR CAST(@CodigoLoja AS VARCHAR) = '''') 
		 RAISERROR (''CodigoLoja está nulo ou em braco'', 16, 1);

	if @@FETCH_STATUS = 0  
		UPDATE CLIENTE SET
				CLICAR = @Cargo,
				CLICEL = @Celular,
				CLICEP = @CEP,
				CLICID = @Cidade,
				CLICPFCGC = @CPFCNPJ,
				CLIDTNAS = @Nascimento,
				CLIDES = @Nome,
				CLIDIAFEC = @DiaVencimento,
				CLIEMAIL = @Email,
				CLIEND = @Endereco,
				CLIEST = @UF,
				CLIESTCIV = @EstadoCivil,
				CLIFAX = @Fax,
				CLINAT = @Naturalidade,
				CLINUM = @NumeroEndereco,
				CLIOBS = @Observacao,
				CLIRES = @Restricoes,
				CLIRGEXP = @OrgaoExpedidorRG,
				CLIRGCGF = @InscricaoEstadualRG,
				CLISAL = @Salario,
				CLISEX = @SexoCliente,
				CLITEL = @Telefone1,
				CLITEL2 = @Telefone2,
				CLIPFPJ = @TipoPessoa,
				STACOD = @CodigoStatus,
				LOJCOD = @CodigoLoja,
				CLI_CHAVE_RETAGUARDA = @ChaveRetaguarda,
				CLI_VERSAO_RETAGUARDA = @VersaoRetaguarda ,
				CLI_ORIGEM_ALTERACAO = ''ERP'',
				CLIDTALT = getdate()
		  WHERE CURRENT OF cr_cliente_cartao;
		  
     ELSE
           INSERT INTO CLIENTE(CLICOD, CLICAR,CLICEL,CLICEP,CLICID,CLICPFCGC,CLIDTNAS,CLIDES,CLIDIAFEC,CLIEMAIL,CLIEND,CLIEST,CLIESTCIV,CLIFAX,CLINAT,CLINUM,CLIOBS,CLIRES,CLIRGEXP,CLIRGCGF,CLISAL,CLISEX,CLITEL,CLITEL2,CLIPFPJ,STACOD,LOJCOD,CLI_CHAVE_RETAGUARDA,CLI_VERSAO_RETAGUARDA, CLI_ORIGEM_ALTERACAO, CLIDTALT)
           values(@CodigoCliente, @Cargo,@Celular,@CEP,@Cidade,@CPFCNPJ,@Nascimento,@Nome,@DiaVencimento,@Email,@Endereco,@UF,@EstadoCivil,@Fax,@Naturalidade,@NumeroEndereco,@Observacao,@Restricoes,@OrgaoExpedidorRG,@InscricaoEstadualRG,@Salario,@SexoCliente,@Telefone1,@Telefone2,@TipoPessoa,@CodigoStatus,@CodigoLoja,@ChaveRetaguarda,@VersaoRetaguarda, ''ERP'', getdate());

  	  close cr_cliente_cartao;
  	  DEALLOCATE cr_cliente_cartao;

END TRY

BEGIN CATCH
  
    close cr_cliente_cartao;
    DEALLOCATE cr_cliente_cartao;

    SELECT
        (CAST(ERROR_NUMBER()AS NVARCHAR(20) ) + '' - '' + ERROR_MESSAGE() ) AS ErrorMessage;
        
END CATCH;



' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SP_AUTORIZADOR_GERA_NSU]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE procedure [dbo].[SP_AUTORIZADOR_GERA_NSU]
as
begin
      declare @NewSeqValue int
      set NOCOUNT ON
      insert into NSU_AUTORIZADOR default values
      set @NewSeqValue = scope_identity()
      delete from NSU_AUTORIZADOR WITH (READPAST)

return @NewSeqValue

end

' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SP_AUTORIZADOR_LIMITE_SALDO]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE PROCEDURE [dbo].[SP_AUTORIZADOR_LIMITE_SALDO]
(
  @CodigoCliente  				INT,
  @LimiteConcedido 				NUMERIC(15,2),
  @SaldoExtratoAnterior  		NUMERIC(15,2),
  @PagamentoExtratoAnterior  	NUMERIC(15,2),
  @CompraParcelasMes  			NUMERIC(15,2),
  @EncargosRefinanciamento 		NUMERIC(15,2),
  @EncargosMora  				NUMERIC(15,2),
  @EncargosMultas 				NUMERIC(15,2),
  @Ajustes 						NUMERIC(15,2),
  @TotalExtrato  				NUMERIC(15,2),
  @PagamentoMinimo 				NUMERIC(15,2),
  @BonusAcumulado  				NUMERIC(15,2),
  @Multas  						NUMERIC(15,2),
  @LimiteDisponivel 			NUMERIC(15,2),
  @Vencimento  					DATETIME,
  @ChaveRetaguarda 				INT,
  @VersaoRetaguarda  			INT
)

AS

BEGIN TRY
  
  declare cr_limite_saldo cursor for SELECT * FROM LIMITE_SALDO
         WHERE CLICOD = @CodigoCliente
         for update;

  open cr_limite_saldo;
  fetch next from cr_limite_saldo;

  if (CAST(@CodigoCliente AS VARCHAR) is NULL OR CAST(@CodigoCliente AS VARCHAR) = '''') 
		 RAISERROR (''CodigoCliente está nulo ou em braco'', 16, 1);

  if (CAST(@LimiteConcedido AS VARCHAR) is NULL OR CAST(@LimiteConcedido AS VARCHAR) = '''')
		 RAISERROR (''LimiteConcedido está nulo ou em braco'', 16, 1);

  if (CAST(@PagamentoExtratoAnterior AS VARCHAR) is NULL OR CAST(@PagamentoExtratoAnterior AS VARCHAR) = '''')
		 RAISERROR (''PagamentoExtratoAnterior está nulo ou em braco'', 16, 1);

  if (CAST(@CompraParcelasMes AS VARCHAR) is NULL OR CAST(@CompraParcelasMes AS VARCHAR) = '''') 
		 RAISERROR (''CompraParcelasMes está nulo ou em braco'', 16, 1);

  if (CAST(@EncargosRefinanciamento AS VARCHAR) is NULL OR CAST(@EncargosRefinanciamento AS VARCHAR) = '''')
		 RAISERROR (''EncargosRefinanciamento está nulo ou em braco'', 16, 1);

  if (CAST(@EncargosMora AS VARCHAR) is NULL OR CAST(@EncargosMora AS VARCHAR) = '''')
		 RAISERROR (''EncargosMora está nulo ou em braco'', 16, 1);

  if (CAST(@EncargosMultas AS VARCHAR) is NULL OR CAST(@EncargosMultas AS VARCHAR) = '''')
		 RAISERROR (''EncargosMultas está nulo ou em braco'', 16, 1);

  if (CAST(@Ajustes AS VARCHAR) is NULL OR CAST(@Ajustes AS VARCHAR) = '''')
		 RAISERROR (''Ajustes está nulo ou em braco'', 16, 1);

  if (CAST(@TotalExtrato AS VARCHAR) is NULL OR CAST(@TotalExtrato AS VARCHAR) = '''')
		 RAISERROR (''TotalExtrato está nulo ou em braco'', 16, 1);

  if (CAST(@PagamentoMinimo AS VARCHAR) is NULL OR CAST(@PagamentoMinimo AS VARCHAR) = '''')
		 RAISERROR (''PagamentoMinimo está nulo ou em braco'', 16, 1);

  if (CAST(@BonusAcumulado AS VARCHAR) is NULL OR CAST(@BonusAcumulado AS VARCHAR) = '''')
		 RAISERROR (''BonusAcumulado está nulo ou em braco'', 16, 1);

  if (CAST(@Multas AS VARCHAR) is NULL OR CAST(@Multas AS VARCHAR) = '''')
		 RAISERROR (''Multas está nulo ou em braco'', 16, 1);

  if (CAST(@LimiteDisponivel AS VARCHAR) is NULL OR CAST(@LimiteDisponivel AS VARCHAR) = '''')
		 RAISERROR (''LimiteDisponivel está nulo ou em braco'', 16, 1);

  if (CAST(@Vencimento AS VARCHAR) is NULL OR CAST(@Vencimento AS VARCHAR) = '''')
		 RAISERROR (''Vencimento está nulo ou em braco'', 16, 1);

  if (CAST(@SaldoExtratoAnterior AS VARCHAR) is NULL OR CAST(@SaldoExtratoAnterior AS VARCHAR) = '''')
		 RAISERROR (''SaldoExtratoAnterior está nulo ou em braco'', 16, 1);

  if @@FETCH_STATUS = 0  
		UPDATE LIMITE_SALDO SET
		 LSDVLRLIM = @LimiteConcedido,
		 LSDVLRPGTEXTANT = @PagamentoExtratoAnterior,
		 LSDVLRCOMPRAMES = @CompraParcelasMes,
		 LSDVLRENCREF = @EncargosRefinanciamento,
		 LSDVLRENCMOR = @EncargosMora,
		 LSDVLRENCMUL = @EncargosMultas,
		 LSDVLRAJU = @Ajustes,
		 LSDVLRTOTEXT = @TotalExtrato,
		 LSDVLRPGTMIN = @PagamentoMinimo,
		 LSDVLRBONACU = @BonusAcumulado,
		 LSDVLRMULT = @Multas,
		 LSDVLRLIMDISP = @LimiteDisponivel,
		 LSDDTVEN = @Vencimento,
		 LSDVLRSALEXTANT = @SaldoExtratoAnterior,
		 LSD_CHAVE_RETAGUARDA = @ChaveRetaguarda,
		 LSD_VERSAO_RETAGUARDA = @VersaoRetaguarda ,
		 LSD_ORIGEM_ALTERACAO = ''ERP'',
		 LSD_DATA_ALTERACAO = getdate()
	  WHERE CURRENT OF cr_limite_saldo;

  else
	 INSERT INTO LIMITE_SALDO(CLICOD,LSDVLRLIM,LSDVLRPGTEXTANT,LSDVLRCOMPRAMES,LSDVLRENCREF,
	 LSDVLRENCMOR,LSDVLRENCMUL,LSDVLRAJU,LSDVLRTOTEXT,LSDVLRPGTMIN,LSDVLRBONACU,LSDVLRMULT,LSDVLRLIMDISP,LSDDTVEN, LSDVLRSALEXTANT, LSD_CHAVE_RETAGUARDA, LSD_VERSAO_RETAGUARDA, LSD_ORIGEM_ALTERACAO, LSD_DATA_ALTERACAO)
		 values(@CodigoCliente,@LimiteConcedido,@PagamentoExtratoAnterior,
		 @CompraParcelasMes,@EncargosRefinanciamento,@EncargosMora,@EncargosMultas,@Ajustes,@TotalExtrato,@PagamentoMinimo,
		 @BonusAcumulado,@Multas,@LimiteDisponivel,@Vencimento,@SaldoExtratoAnterior,@ChaveRetaguarda,@VersaoRetaguarda,''ERP'',getdate());

  close cr_limite_saldo;
  DEALLOCATE cr_limite_saldo;

END TRY

BEGIN CATCH
  
    close cr_limite_saldo;
    DEALLOCATE cr_limite_saldo;

    SELECT
        (CAST(ERROR_NUMBER()AS NVARCHAR(20) ) + '' - '' + ERROR_MESSAGE() ) AS ErrorMessage;
        
END CATCH;



' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SP_LIMITE_SALDO_ATUALIZACAO]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

CREATE PROCEDURE [dbo].[SP_LIMITE_SALDO_ATUALIZACAO]
(
   @CodigoCliente 	INT,
   @LimiteConcedido  numeric (15,2),
   @BonusAcumulado   numeric (15,2),
   @LimiteDisponivel numeric (15,2),
   @ChaveRetaguarda  INT,
   @VersaoRetaguarda INT
)
AS

BEGIN TRY

	if (CAST(@CodigoCliente AS VARCHAR) is NULL OR CAST(@CodigoCliente AS VARCHAR) = '''')
	   RAISERROR (''CodigoCliente está nulo ou em braco'', 16, 1); 
	

	if (CAST(@LimiteDisponivel AS VARCHAR) is NULL OR CAST(@LimiteDisponivel AS VARCHAR) = '''') 
		RAISERROR (''LimiteDisponivel está nulo ou em braco'', 16, 1); 

	if (CAST(@BonusAcumulado AS VARCHAR) is NULL OR CAST(@BonusAcumulado AS VARCHAR) = '''') AND (CAST(@LimiteConcedido AS VARCHAR) is null 
			OR CAST(@LimiteConcedido AS VARCHAR) = '''') 
		RAISERROR (''BonusAcumulado está nulo ou em braco'', 16, 1); 


	if (CAST(@BonusAcumulado AS VARCHAR) is NULL OR CAST(@BonusAcumulado AS VARCHAR) = '''') AND (CAST(@LimiteConcedido AS VARCHAR) is not null 
			or CAST(@LimiteConcedido AS VARCHAR) <> '''') 
	 UPDATE LIMITE_SALDO SET
		 LSDVLRLIM = @LimiteConcedido,
		 LSDVLRLIMDISP =@LimiteDisponivel,
		 LSD_CHAVE_RETAGUARDA = @ChaveRetaguarda,
		 LSD_VERSAO_RETAGUARDA = @VersaoRetaguarda ,
		 LSD_ORIGEM_ALTERACAO = ''ERP'',
		 LSD_DATA_ALTERACAO = getdate()
	  WHERE CLICOD = @CodigoCliente;

	else		

	  if (CAST(@BonusAcumulado AS VARCHAR) is NOT NULL OR CAST(@BonusAcumulado AS VARCHAR) <> '''') AND (CAST(@LimiteConcedido AS VARCHAR) is null 
				or CAST(@LimiteConcedido AS VARCHAR) = '''') 
		  UPDATE LIMITE_SALDO SET
			 LSDVLRBONACU = @BonusAcumulado,
			 LSDVLRLIMDISP = @LimiteDisponivel,
			 LSD_CHAVE_RETAGUARDA = @ChaveRetaguarda,
			 LSD_VERSAO_RETAGUARDA = @VersaoRetaguarda ,
			 LSD_ORIGEM_ALTERACAO = ''ERP'',
			 LSD_DATA_ALTERACAO = getdate()
		  WHERE CLICOD = @CodigoCliente;
	 else
		UPDATE LIMITE_SALDO SET
			 LSDVLRLIM = @LimiteConcedido,
			 LSDVLRBONACU = @BonusAcumulado,
			 LSDVLRLIMDISP = @LimiteDisponivel,
			 LSD_CHAVE_RETAGUARDA = @ChaveRetaguarda,
			 LSD_VERSAO_RETAGUARDA = @VersaoRetaguarda ,
			 LSD_ORIGEM_ALTERACAO = ''ERP'',
			 LSD_DATA_ALTERACAO = getdate()
		  WHERE CLICOD = @CodigoCliente;

END TRY

BEGIN CATCH
    SELECT
        (CAST(ERROR_NUMBER()AS NVARCHAR(20) ) + '' - '' + ERROR_MESSAGE() ) AS ErrorMessage;
END CATCH;






' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SP_IMPORTACAO_GRUPO_PRODUTO]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
create PROCEDURE [dbo].[SP_IMPORTACAO_GRUPO_PRODUTO]
(
  @vCodigo       int,
  @vCodigoSecao  int,
  @vDescricao    VARCHAR(60)

)
AS
begin
  DECLARE @secao_id int  
  SET @secao_id = (SELECT SECID FROM SECAO WHERE SECCOD = @vCodigoSecao ) 
  
  IF (@secao_id > 0)
  IF (SELECT COUNT(*) FROM GRUPO_PRODUTO WHERE GRPCOD=@vCodigo AND SECCOD = @vCodigoSecao ) > 0
  UPDATE GRUPO_PRODUTO SET
           GRPDES = @vDescricao
       WHERE GRPCOD = @vCodigo AND SECCOD = @vCodigoSecao;
  ELSE
    INSERT INTO GRUPO_PRODUTO(GRPCOD, SECCOD, GRPDES)
       values(@vCodigo ,@vCodigoSecao ,@vDescricao);
  
END

' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SP_IMPORTACAO_PRODUTO]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE PROCEDURE [dbo].[SP_IMPORTACAO_PRODUTO]
(
  @V_PROCOD        VARCHAR(16),
  @V_PRODES        VARCHAR(45),
  @V_PRODESRDZ     VARCHAR(20),
  @V_SECCOD        CHAR,
  @V_TRBID         VARCHAR(3),
  @V_PROPESVAR     CHAR,
  @V_PROCOMTIP     CHAR,
  @V_PROCOMCAP     numeric (15,2),
  @V_PROCOMPRO     numeric (15,2),
  @V_PROCOMVEN     numeric (15,2),
  @V_PROVLD        VARCHAR(3),
  @V_LOCCOD        CHAR,
  @V_PROFRTLOJ     CHAR,
  @V_PROESTMIN     numeric (15,3),
  @V_PROESTMAX     numeric (15,3),
  @V_FORCOD        CHAR,
  @V_PROQTDETQ     numeric (15,2),
  @V_PROUNID       VARCHAR(3),
  @V_PROFLGALT     CHAR,
  @V_PROTABA       CHAR,
  @V_PROBONTIP     CHAR,
  @V_PROBONFAT     numeric (15,3),
  @V_PROCTREST     CHAR,
  @V_PRONUMSER     CHAR,
  @V_PROESP        CHAR,
  @V_PROCOMP       CHAR,
  @V_PROENVBAL     CHAR,
  @V_PROCTRVLD     CHAR,
  @V_PRODATCADINC  datetime,
  @V_PRODATFORLIN  datetime,
  @V_PRODATCADALT  datetime,
  @V_FUNCOD        CHAR,
  @V_PROMIX        CHAR,
  @V_PRODESVAR     CHAR,
  @V_PROEND        VARCHAR(20),
  @V_GRPCOD        CHAR,
  @V_SGRCOD        CHAR,
  @V_PROITEEMB     numeric (15,3),
  @V_PROQTDMAXVDA  numeric (15,3),
  @V_PROPESBRT     numeric (9,3),
  @V_PROPESLIQ     numeric (9,3),
  @V_PROUNDREF     CHAR,
  @V_PROMEDREF     numeric (15,3),
  @V_PROFORLIN     CHAR
)
AS

begin

DECLARE @id int
DECLARE @id_secao int
DECLARE @id_grupo int
DECLARE @id_subgrupo int

 SET @id_secao = (SELECT SECID FROM SECAO WHERE SECCOD = @V_SECCOD )

 SET @id_grupo = (SELECT GRPID FROM GRUPO_PRODUTO G WHERE G.GRPCOD = @V_GRPCOD AND G.SECCOD= @V_SECCOD )

 SET @id_subgrupo = (SELECT S.SGPID FROM SUBGRUPO_PRODUTO S WHERE S.SGPCOD = @V_SGRCOD AND S.GRPCOD= @id_grupo )

 IF (@id_secao is null)
	SET @id_secao = 0

   IF (SELECT COUNT(*) FROM PRODUTO WHERE PROCOD=@V_PROCOD) > 0
      UPDATE PRODUTO SET
       PROCOD = @V_PROCOD               ,
       PRODES = @V_PRODES               ,
       PRODESRDZ = @V_PRODESRDZ         ,
       SECCOD = @id_secao               ,
       TRBID = @V_TRBID                 ,
       PROPESVAR = @V_PROPESVAR         ,
       PROCOMTIP = @V_PROCOMTIP         ,
       PROCOMCAP = @V_PROCOMCAP         ,
       PROCOMPRO = @V_PROCOMPRO         ,
       PROCOMVEN = @V_PROCOMVEN         ,
       PROVLD = @V_PROVLD               ,
       LOCCOD = @V_LOCCOD               ,
       PROESTMIN = @V_PROESTMIN         ,
       PROFRTLOJ = @V_PROFRTLOJ         ,
       PROESTMAX = @V_PROESTMAX         ,
       FORCOD = @V_FORCOD               ,
       PROQTDETQ = @V_PROQTDETQ         ,
       PROUNID = @V_PROUNID             ,
       PROBONTIP = @V_PROBONTIP         ,
       PROFLGALT = @V_PROFLGALT         ,
       PROTABA = @V_PROTABA             ,
       PROBONFAT = @V_PROBONFAT         ,
       PROCTREST = @V_PROCTREST         ,
       PROESP    = @V_PROESP            ,
       PRONUMSER = @V_PRONUMSER         ,
       PROCOMP   = @V_PROCOMP           ,
       PROENVBAL = @V_PROENVBAL         ,
       PROCTRVLD = @V_PROCTRVLD         ,
       PRODATCADALT= @V_PRODATCADALT    ,
       FUNCOD    = @V_FUNCOD            ,
       PROMIX    = @V_PROMIX            ,
       PRODESVAR = @V_PRODESVAR         ,
       PROEND    = @V_PROEND            ,
       SGPCOD        = @id_subgrupo     ,
       GRPCOD        = @id_grupo        ,
       PROPESBRT   = @V_PROPESBRT       ,
       PROITEEMB     = @V_PROITEEMB     ,
       PROQTDMAXVDA = @V_PROQTDMAXVDA   ,
       PROPESLIQ     = @V_PROPESLIQ     ,
       PROUNDREF    = @V_PROUNDREF      ,
       PROMEDREF    = @V_PROMEDREF      ,
       PRODATFORLIN  = @V_PRODATFORLIN  ,
       PROFORLIN = @V_PROFORLIN
       WHERE PROCOD = @V_PROCOD;
  ELSE
    INSERT INTO PRODUTO(PROCOD         ,PRODES          ,PRODESRDZ       ,SECCOD          ,TRBID,
          PROPESVAR      ,PROCOMTIP       ,PROCOMCAP       ,PROCOMPRO,
          PROCOMVEN      ,PROVLD          ,LOCCOD,
          PROFRTLOJ       ,PROESTMIN       ,PROESTMAX       ,FORCOD,
          PROQTDETQ       ,
          PROUNID         ,PROFLGALT       ,PROTABA         ,PROBONTIP,
          PROBONFAT      ,PROCTREST       ,PRONUMSER,
          PROESP         ,PROCOMP         ,PROENVBAL       ,PROCTRVLD       ,
          PRODATCADINC    ,FUNCOD          ,PROMIX,
          PRODESVAR      ,PROEND          ,SGPCOD,
          GRPCOD         ,PROITEEMB       ,PROQTDMAXVDA    ,PROPESBRT       ,PROPESLIQ,
          PROUNDREF      ,PROMEDREF       ,PRODATFORLIN    ,PROFORLIN)
       values(@V_PROCOD       ,@V_PRODES        ,@V_PRODESRDZ     ,@id_secao        ,@V_TRBID,
          @V_PROPESVAR    ,@V_PROCOMTIP     ,@V_PROCOMCAP     ,@V_PROCOMPRO,
          @V_PROCOMVEN    ,@V_PROVLD        ,@V_LOCCOD,
          @V_PROFRTLOJ     ,@V_PROESTMIN     ,@V_PROESTMAX     ,@V_FORCOD,
          @V_PROQTDETQ     ,
          @V_PROUNID       ,@V_PROFLGALT     ,@V_PROTABA       ,@V_PROBONTIP,
          @V_PROBONFAT    ,@V_PROCTREST     ,@V_PRONUMSER,
          @V_PROESP       ,@V_PROCOMP       ,@V_PROENVBAL     ,@V_PROCTRVLD     ,
          @V_PRODATCADINC  ,@V_FUNCOD        ,@V_PROMIX,
          @V_PRODESVAR    ,@V_PROEND        ,@id_subgrupo,
          @id_grupo       ,@V_PROITEEMB     ,@V_PROQTDMAXVDA  ,@V_PROPESBRT     ,@V_PROPESLIQ,
          @V_PROUNDREF    ,@V_PROMEDREF     ,@V_PRODATFORLIN  ,@V_PROFORLIN);


       IF (@V_FORCOD <> 0)
	    IF (SELECT COUNT(*) FROM FORNECEDOR WHERE FORCOD=@V_FORCOD) = 0
            insert into FORNECEDOR (FORCOD) values(@V_FORCOD);

             insert into PRODUTO_FORNECEDOR (PROCOD,FORCOD,PRFUNID,PRFQTD,PRFNIVEL)
                values(@V_PROCOD,@V_FORCOD,@V_PROUNID,1,''P'');

END;

'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SP_SECAO]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
create PROCEDURE [dbo].[SP_SECAO]

(@CODIGO  INT,
 @DESCRICAO  VARCHAR (30)
) AS

BEGIN

DECLARE @id int

   IF (SELECT COUNT(*) FROM SECAO WHERE SECCOD=@CODIGO) > 0
     UPDATE SECAO SET SECCOD = @CODIGO, SECDES = @DESCRICAO WHERE SECCOD = @CODIGO ELSE
     INSERT INTO SECAO(SECCOD, SECDES)
            VALUES(@CODIGO, @DESCRICAO)

END;

'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[v_venda_loja_secao]'))
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[v_venda_loja_secao]
AS
SELECT     LOJCOD, TRNDAT, SECCOD, MAX(SECDES) AS SECDES, SUM(QTD_VENDIDA) AS QTD_VENDIDA, SUM(VLR_FAT) AS VLR_FAT, SUM(VLR_CST)
                      AS TOT_CST, SUM(TOT_CLI) AS TOT_CLI
FROM         (SELECT     T.LOJCOD, T.TRNDAT, P.SECCOD, S.SECDES, SUM(I.ITVQTDVDA) AS QTD_VENDIDA, SUM(I.ITVVLRTOT) AS VLR_FAT,
                                              SUM(I.ITVPRCCST * I.ITVQTDVDA) AS VLR_CST, COUNT(*) AS TOT_CLI
                       FROM          dbo.TRANSACAO AS T INNER JOIN
                                              dbo.ITEM_VENDA AS I ON T.LOJCOD = I.LOJCOD AND T.TRNSEQ = I.TRNSEQ AND T.CXANUM = I.CXANUM AND T.TRNDAT = I.TRNDAT AND
                                              T.TRNTIP = ''1'' AND I.ITVTIP <> ''2'' LEFT OUTER JOIN
                                              dbo.PRODUTO AS P ON I.PROCOD = P.PROCOD INNER JOIN
                                              dbo.SECAO AS S ON P.SECCOD = S.SECCOD
                       WHERE      (T.TRNTIP = ''1'')
                       GROUP BY T.LOJCOD, T.TRNDAT, I.PROCOD, P.SECCOD, S.SECDES) AS vda_secao
GROUP BY LOJCOD, TRNDAT, SECCOD;

'
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SP_IMPORTACAO_STATUS]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE PROCEDURE [dbo].[SP_IMPORTACAO_STATUS]
(
  @V_STACOD  CHAR,
  @V_STADES  VARCHAR,
  @V_STASIT  CHAR
)
AS

BEGIN

IF (SELECT COUNT(*) FROM STATUS WHERE STACOD = @V_STACOD) > 0
      UPDATE STATUS SET STACOD = @V_STACOD, STADES = @V_STADES, STABLC = @V_STASIT
     WHERE STACOD = @V_STACOD;
  ELSE
    INSERT INTO STATUS(STACOD,STADES,STABLC)
                values(@V_STACOD,@V_STADES,@V_STASIT);

END;

'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SP_AUTORIZADOR_STATUS]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE PROCEDURE [dbo].[SP_AUTORIZADOR_STATUS]
(
  @CodigoStatus  	INT,
  @StatusBloqueio 	INT,
  @DescricaoStatus 	VARCHAR(60),
  @TipoBloqueio  	VARCHAR(4),
  @ChaveRetaguarda 	INT,
  @VersaoRetaguarda INT
)
AS

BEGIN TRY

   if (@CodigoStatus is NULL OR @CodigoStatus = '''')
		RAISERROR (''CodigoStatus está nulo ou em braco'', 16, 1);

	if (@StatusBloqueio is NULL OR @StatusBloqueio = '''' OR @StatusBloqueio not in (''0'',''1'',''2'',''3''))
		RAISERROR (''StatusBloqueio está nulo ou em braco ou diferente de 0,1,2,3'', 16, 1);

	if (@DescricaoStatus is NULL OR @DescricaoStatus = '''')
		RAISERROR (''DescricaoStatus está nulo ou em braco'', 16, 1);

	if (@TipoBloqueio is NULL OR @TipoBloqueio = '''')
		RAISERROR (''TipoBloqueio está nulo ou em braco'', 16, 1);

	if exists (select stacod from status where stacod = @CodigoStatus)
	  UPDATE STATUS SET
				STABLC = @StatusBloqueio,
				STADES = @DescricaoStatus,
				STATIPBLOQ = @TipoBloqueio,
				STA_CHAVE_RETAGUARDA = @ChaveRetaguarda,
				STA_VERSAO_RETAGUARDA = @VersaoRetaguarda ,
				STA_ORIGEM_ALTERACAO = ''ERP'',
				STA_DATA_ALTERACAO = getdate()
		  WHERE stacod = @CodigoStatus;
	else
	  INSERT INTO STATUS(STACOD, STABLC, STADES, STATIPBLOQ,STA_CHAVE_RETAGUARDA,STA_VERSAO_RETAGUARDA,STA_ORIGEM_ALTERACAO,STA_DATA_ALTERACAO)
		  values(@CodigoStatus, @StatusBloqueio, @DescricaoStatus,@TipoBloqueio,@ChaveRetaguarda,@VersaoRetaguarda,''ERP'', getdate());
END TRY

BEGIN CATCH
    SELECT
        (CAST(ERROR_NUMBER()AS NVARCHAR(20) ) + '' - '' + ERROR_MESSAGE() ) AS ErrorMessage;
END CATCH;


'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SP_IMPORTACAO_SUBGRUPO_PRODUTO]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE PROCEDURE [dbo].[SP_IMPORTACAO_SUBGRUPO_PRODUTO]
(
  @vCodigo       int,
  @vCodigoGrupo  int,
  @vCodigoSecao  int,
  @vDescricao    VARCHAR(80)
)
AS

begin
 DECLARE @id int
 DECLARE @grupo_id int

 SET @grupo_id = (SELECT GRPID  FROM GRUPO_PRODUTO  WHERE GRPCOD=@vCodigoGrupo AND SECCOD=@vCodigoSecao)

 IF (@grupo_id > 0)
  IF (SELECT COUNT(*) FROM SUBGRUPO_PRODUTO  WHERE SGPCOD=@vCodigo AND GRPCOD=@grupo_id) > 0
    UPDATE SUBGRUPO_PRODUTO SET SGPDES = @vDescricao
       WHERE SGPCOD=@vCodigo AND GRPCOD=@grupo_id;
  ELSE
    INSERT INTO SUBGRUPO_PRODUTO(SGPCOD, GRPCOD, SGPDES)
       values(@vCodigo, @grupo_id, @vDescricao);

END;

'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[v_venda_finalizacao_caixa]'))
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[v_venda_finalizacao_caixa]
AS
select
  transacao.TRNDAT,
  transacao.CXANUM,
  transacao.LOJCOD,
  finalizacao.FZDCOD,
  sum((finalizacao.FZCVLR - finalizacao.FZCCTRVAL))VLRTOT,
  loja.HOLCOD
from transacao
  join finalizacao on(transacao.LOJCOD = finalizacao.LOJCOD
                  and transacao.TRNDAT = finalizacao.TRNDAT
                  and transacao.CXANUM = finalizacao.CXANUM
                  and transacao.TRNSEQ = finalizacao.TRNSEQ)
  join loja on(transacao.LOJCOD = loja.LOJCOD)
  and transacao.TRNTIP = ''1''
group by
  transacao.TRNDAT,
  transacao.CXANUM,
  finalizacao.FZDCOD,
  transacao.LOJCOD,
  loja.HOLCOD;

'
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[v_venda_posicao_loja_dia_cupom]'))
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[v_venda_posicao_loja_dia_cupom]
AS
SELECT     T.TRNDAT, T.TRNSEQ, T.CXANUM, T.LOJCOD, L.HOLCOD, CAST(SUM(i.ITVQTDVDA) AS integer) AS ITEQTD, MAX(f.vlrtot) AS VLRTOT, SUM(i.ITVPRCCST)
                      AS CSTTOT, COUNT(DISTINCT T.TRNSEQ) AS CLIQTD
FROM         dbo.TRANSACAO AS T INNER JOIN
                          (SELECT     TRNDAT, TRNSEQ, CXANUM, LOJCOD, SUM(FZCVLR - FZCCTRVAL) AS vlrtot
                            FROM          dbo.FINALIZACAO
                            GROUP BY TRNDAT, TRNSEQ, CXANUM, LOJCOD) AS f ON f.TRNDAT = T.TRNDAT AND f.TRNSEQ = T.TRNSEQ AND f.CXANUM = T.CXANUM AND
                      f.LOJCOD = T.LOJCOD INNER JOIN
                      dbo.ITEM_VENDA AS i ON i.TRNDAT = T.TRNDAT AND i.TRNSEQ = T.TRNSEQ AND i.CXANUM = T.CXANUM AND i.LOJCOD = T.LOJCOD AND
                      i.ITVTIP = ''1'' AND T.TRNTIP = ''1'' INNER JOIN
                      dbo.LOJA AS L ON T.LOJCOD = L.LOJCOD
WHERE     (T.TRNTIP = ''1'')
GROUP BY T.TRNDAT, T.TRNSEQ, T.CXANUM, T.LOJCOD, T.TRNTIP, L.HOLCOD;

'
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SP_IMPORTACAO_FUNCIONARIO]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE PROCEDURE [dbo].[SP_IMPORTACAO_FUNCIONARIO]
(
  @V_FUNCOD CHAR,
  @V_FUNDES VARCHAR,
  @V_FUNAPE CHAR,
  @V_FUNCAR CHAR,
  @V_FUNCOM numeric(15,2),
  @V_FUNCOM2 numeric(15,2),
  @V_FUNCOM3 numeric(15,2)
)
AS
BEGIN

  IF (SELECT COUNT(*) FROM FUNCIONARIO WHERE FUNCOD = @V_FUNCOD ) > 0

    UPDATE FUNCIONARIO SET FUNCOD  = @V_FUNCOD  ,FUNDES  = @V_FUNDES ,FUNAPE  = @V_FUNAPE,
                           FUNCAR  = @V_FUNCAR  ,FUNCOM  = @V_FUNCOM ,FUNCOM2 = @V_FUNCOM2,
                           FUNCOM3 = @V_FUNCOM3 WHERE FUNCOD  = @V_FUNCOD;
  ELSE
    INSERT INTO FUNCIONARIO(FUNCOD,FUNDES,FUNAPE,FUNCAR,FUNCOM,FUNCOM2,FUNCOM3)
                    values(@V_FUNCOD,@V_FUNDES,@V_FUNAPE,@V_FUNCAR,@V_FUNCOM,@V_FUNCOM2,@V_FUNCOM3);

END;

'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[v_venda_dia_hora_caixa]'))
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[v_venda_dia_hora_caixa]
AS
SELECT     t.TRNDAT, t.LOJCOD, t.CXANUM, t.TRNSEQ, SUBSTRING(t.TRNHOR, 1, 2) + ''-'' + CONVERT(varchar, CONVERT(int, SUBSTRING(t.TRNHOR, 1, 2)) + 1)
                      AS hora, MIN(t.TRNVLR) AS vlrtot, SUM(CAST(i.ITVQTDVDA AS integer)) AS iteqtd, COUNT(DISTINCT t.TRNSEQ) AS cliqtd, l.HOLCOD
FROM         dbo.TRANSACAO AS t INNER JOIN
                      dbo.ITEM_VENDA AS i ON i.TRNSEQ = t.TRNSEQ AND i.TRNDAT = t.TRNDAT AND i.CXANUM = t.CXANUM AND i.LOJCOD = t.LOJCOD AND
                      i.ITVTIP = ''1'' AND t.TRNTIP = ''1'' INNER JOIN
                      dbo.LOJA AS l ON t.LOJCOD = l.LOJCOD
GROUP BY t.TRNDAT, t.LOJCOD, SUBSTRING(t.TRNHOR, 1, 2) + ''-'' + CONVERT(varchar, CONVERT(int, SUBSTRING(t.TRNHOR, 1, 2)) + 1), t.CXANUM, t.TRNSEQ,
                      l.HOLCOD;
'
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[v_venda_produto_mais_vendido]'))
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[v_venda_produto_mais_vendido]
AS
SELECT     T.LOJCOD, T.TRNDAT, IV.PROCOD, MAX(P.PRODES) AS PRODES, SUM(IV.ITVQTDVDA) AS QUANTIDADE, SUM(IV.ITVVLRTOT) AS FATURAMENTO,
                      SUM(IV.ITVPRCCST * IV.ITVQTDVDA) AS CUSTO
FROM         dbo.TRANSACAO AS T INNER JOIN
                      dbo.ITEM_VENDA AS IV ON T.TRNSEQ = IV.TRNSEQ AND T.CXANUM = IV.CXANUM AND T.TRNDAT = IV.TRNDAT AND T.LOJCOD = IV.LOJCOD AND
                      T.TRNTIP = ''1'' AND IV.ITVTIP <> ''2'' INNER JOIN
                      dbo.PRODUTO AS P ON IV.PROCOD = P.PROCOD
WHERE     (T.TRNTIP = ''1'')
GROUP BY T.LOJCOD, T.TRNDAT, IV.PROCOD;




'
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_troco_premiado]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE PROCEDURE [dbo].[sp_troco_premiado]
	/*Declara variaveis de TROCO_PREMIADO_REMESSA*/
	@numeroRemessa int,
	@dataGeracao datetime,
	/*Declara variaveis de TROCO_PREMIADO*/
	@numeroDaSorte int,
	@numeroProposta bigint,
	@status varchar(1),
	@sequencial int

AS
BEGIN  	IF	(SELECT COUNT(*) FROM TROCO_PREMIADO_REMESSA WHERE TPRNUMREM = @numeroRemessa ) = 0
	BEGIN
		INSERT INTO TROCO_PREMIADO_REMESSA(TPRNUMREM, TPRDATGER)
		values( @numeroRemessa, @dataGeracao)
	END
	INSERT INTO TROCO_PREMIADO(TPMNUM, TPMPROP, TPMSTA, TPRNUMREM, TPMSEQ)
	values( @numeroDaSorte, @numeroProposta, @status, @numeroRemessa, @sequencial)
END;

'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SP_IMPORTACAO_PRECO]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE PROCEDURE [dbo].[SP_IMPORTACAO_PRECO]
(
  @vCodigoLoja int,
  @vCodigoProduto int,
  @vPrcVenda1 numeric (15,2),
  @vPrcOferta1 numeric (15,2),
  @vPrcVenda2 numeric (15,2),
  @vPrcOferta2 numeric (15,2),
  @vPrcVenda3 numeric (15,2),
  @vPrcOferta3 numeric (15,2),
  @vMargem1 numeric (15,2),
  @vMargem2 numeric (15,2),
  @vMargem3 numeric (15,2),
  @vCusto numeric (15,2),
  @vQtdMinPrc2 numeric (15,2),
  @vQtdMinPrc3 numeric (15,3),
  @vDataUltReaPrc1 datetime,
  @vDataUltReaPrc2 datetime,
  @vDataUltReaPrc3 datetime,
  @vDescontoMaximo numeric (15,2),
  @vPermiteDesconto CHAR
)
AS

begin

 DECLARE @id int
 SELECT @id = MAX(P.PRCID)+1 FROM PRECO P

  IF (SELECT COUNT(*) FROM PRECO WHERE LOJCOD=@vCodigoLoja AND PROCOD = @vCodigoProduto) > 0
      UPDATE PRECO SET
           PRCVDAVAR = @vPrcVenda1,
           PRCOFEVAR = @vPrcOferta1,
           PRCMRG1 = @vMargem1,
           PRCVDA2 = @vPrcVenda2,
           PRCOFE2 = @vPrcOferta2,
           PRCMRG2 = @vMargem2,
           PRCQTDMINPRC2 = @vQtdMinPrc2,
           PRCVDA3 = @vPrcVenda3,
           PRCOFE3 = @vPrcOferta3,
           PRCMRG3 = @vMargem3,
           PRCQTDMINPRC3 = @vQtdMinPrc3,
           PRCCST = @vCusto,
           PRCDTULTRE = @vDataUltReaPrc1,
           PRCDTULTRE2 = @vDataUltReaPrc2,
           PRCDTULTRE3 = @vDataUltReaPrc3,
           PRCDCNMAX = @vDescontoMaximo,
           PRCPERDCN = @vPermiteDesconto
       WHERE LOJCOD = @vCodigoLoja AND PROCOD = @vCodigoProduto;
  ELSE
    INSERT INTO PRECO(PRCID,LOJCOD,PROCOD,PRCVDAVAR,PRCOFEVAR,PRCMRG1,PRCVDA2,PRCOFE2,PRCMRG2,PRCQTDMINPRC2,PRCVDA3,PRCOFE3,PRCMRG3,PRCQTDMINPRC3,PRCCST,PRCDTULTRE,PRCDTULTRE2,PRCDTULTRE3,PRCDCNMAX,PRCPERDCN)
       values(@id,@vCodigoLoja,@vCodigoProduto,@vPrcVenda1,@vPrcOferta1,@vMargem1,@vPrcVenda2,@vPrcOferta2,@vMargem2,@vQtdMinPrc2,@vPrcVenda3,@vPrcOferta3,@vMargem3,@vQtdMinPrc3,@vCusto,@vDataUltReaPrc1,@vDataUltReaPrc2,@vDataUltReaPrc3,@vDescontoMaximo,@vPermiteDesconto);

END;

'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SP_IMPORTACAO_CODIGO_AUXILIAR]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE PROCEDURE [dbo].[SP_IMPORTACAO_CODIGO_AUXILIAR]
(
@V_PROCODAUX VARCHAR,
@V_PROCOD VARCHAR
) AS

begin

  IF	(SELECT COUNT(*) FROM PRODUTOAUX WHERE PROCODAUX = @V_PROCODAUX ) > 0
    update PRODUTOAUX set PROCODAUX = @V_PROCODAUX, PROCOD = @V_PROCOD where PROCODAUX = @V_PROCODAUX;
 else
   insert into PRODUTOAUX(PROCODAUX,PROCOD) values(@V_PROCODAUX,@V_PROCOD);

END;

'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SP_IMPORTACAO_RAMO]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE PROCEDURE [dbo].[SP_IMPORTACAO_RAMO]

(@CODIGO  INT,
 @DESCRICAO VARCHAR (30)
)
AS

BEGIN
   IF (SELECT COUNT(*) FROM RAMO WHERE RAMCOD = @CODIGO) > 0
     UPDATE RAMO SET RAMCOD = @CODIGO, RAMDES = @DESCRICAO WHERE RAMCOD = @CODIGO;
 ELSE
     INSERT INTO RAMO(RAMCOD, RAMDES) VALUES(@CODIGO, @DESCRICAO);
 END;

'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[v_venda_dia_hora]'))
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[v_venda_dia_hora]
AS
SELECT     TRNDAT, hora, LOJCOD, HOLCOD, SUM(vlrtot) AS vlrtot, SUM(iteqtd) AS iteqtd, SUM(cliqtd) AS cliqtd
FROM         dbo.v_venda_dia_hora_caixa
GROUP BY TRNDAT, hora, LOJCOD, HOLCOD;

'
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[v_venda_finalizacao]'))
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[v_venda_finalizacao]
AS
SELECT
  TRNDAT,
  LOJCOD,
  HOLCOD,
  FZDCOD,
  SUM(VLRTOT) AS VLRTOT
FROM
  v_venda_finalizacao_caixa
GROUP BY
  TRNDAT,
  LOJCOD,
  HOLCOD,
  FZDCOD;

'
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[v_venda_posicao_loja_dia]'))
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[v_venda_posicao_loja_dia]
AS
SELECT
  TRNDAT,
  LOJCOD,
  HOLCOD,
  SUM(ITEQTD) AS ITEQTD,
  SUM(VLRTOT) AS VLRTOT,
  SUM(CLIQTD) AS CLIQTD,
  SUM(CSTTOT) AS CSTTOT
FROM
  v_venda_posicao_loja_dia_cupom
GROUP BY
  TRNDAT,
  LOJCOD,
  HOLCOD;

'
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_FINALIZACAO_CLIENTE]') AND parent_object_id = OBJECT_ID(N'[dbo].[FINALIZACAO]'))
ALTER TABLE [dbo].[FINALIZACAO]  WITH CHECK ADD  CONSTRAINT [FK_FINALIZACAO_CLIENTE] FOREIGN KEY([CLICOD])
REFERENCES [dbo].[CLIENTE] ([CLICOD])
GO
ALTER TABLE [dbo].[FINALIZACAO] CHECK CONSTRAINT [FK_FINALIZACAO_CLIENTE]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_FINALIZACAO_LOJA]') AND parent_object_id = OBJECT_ID(N'[dbo].[FINALIZACAO]'))
ALTER TABLE [dbo].[FINALIZACAO]  WITH CHECK ADD  CONSTRAINT [FK_FINALIZACAO_LOJA] FOREIGN KEY([LOJCOD])
REFERENCES [dbo].[LOJA] ([LOJCOD])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[FINALIZACAO] CHECK CONSTRAINT [FK_FINALIZACAO_LOJA]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_FINALIZACAO_TRANSACAO]') AND parent_object_id = OBJECT_ID(N'[dbo].[FINALIZACAO]'))
ALTER TABLE [dbo].[FINALIZACAO]  WITH CHECK ADD  CONSTRAINT [FK_FINALIZACAO_TRANSACAO] FOREIGN KEY([LOJCOD], [TRNDAT], [CXANUM], [TRNSEQ])
REFERENCES [dbo].[TRANSACAO] ([LOJCOD], [TRNDAT], [CXANUM], [TRNSEQ])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[FINALIZACAO] CHECK CONSTRAINT [FK_FINALIZACAO_TRANSACAO]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FIDELIZACAO_CLIENTE]') AND parent_object_id = OBJECT_ID(N'[dbo].[FIDELIZACAO]'))
ALTER TABLE [dbo].[FIDELIZACAO]  WITH CHECK ADD  CONSTRAINT [FIDELIZACAO_CLIENTE] FOREIGN KEY([CLICOD])
REFERENCES [dbo].[CLIENTE] ([CLICOD])
GO
ALTER TABLE [dbo].[FIDELIZACAO] CHECK CONSTRAINT [FIDELIZACAO_CLIENTE]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_LIMITE_S_REFERENCE_CLIENTE]') AND parent_object_id = OBJECT_ID(N'[dbo].[LIMITE_SALDO]'))
ALTER TABLE [dbo].[LIMITE_SALDO]  WITH CHECK ADD  CONSTRAINT [FK_LIMITE_S_REFERENCE_CLIENTE] FOREIGN KEY([CLICOD])
REFERENCES [dbo].[CLIENTE] ([CLICOD])
GO
ALTER TABLE [dbo].[LIMITE_SALDO] CHECK CONSTRAINT [FK_LIMITE_S_REFERENCE_CLIENTE]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_CARTAO_C_REFERENCE_CLIENTE]') AND parent_object_id = OBJECT_ID(N'[dbo].[CARTAO_CREDITO]'))
ALTER TABLE [dbo].[CARTAO_CREDITO]  WITH CHECK ADD  CONSTRAINT [FK_CARTAO_C_REFERENCE_CLIENTE] FOREIGN KEY([CLICOD])
REFERENCES [dbo].[CLIENTE] ([CLICOD])
GO
ALTER TABLE [dbo].[CARTAO_CREDITO] CHECK CONSTRAINT [FK_CARTAO_C_REFERENCE_CLIENTE]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_CARTAO_C_REFERENCE_STATUS]') AND parent_object_id = OBJECT_ID(N'[dbo].[CARTAO_CREDITO]'))
ALTER TABLE [dbo].[CARTAO_CREDITO]  WITH CHECK ADD  CONSTRAINT [FK_CARTAO_C_REFERENCE_STATUS] FOREIGN KEY([STACOD])
REFERENCES [dbo].[STATUS] ([STACOD])
GO
ALTER TABLE [dbo].[CARTAO_CREDITO] CHECK CONSTRAINT [FK_CARTAO_C_REFERENCE_STATUS]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ITEM_DEVOLUCAO_DEVOLUCAO]') AND parent_object_id = OBJECT_ID(N'[dbo].[ITEM_DEVOLUCAO]'))
ALTER TABLE [dbo].[ITEM_DEVOLUCAO]  WITH CHECK ADD  CONSTRAINT [FK_ITEM_DEVOLUCAO_DEVOLUCAO] FOREIGN KEY([DEVCOD])
REFERENCES [dbo].[DEVOLUCAO] ([DEVCOD])
GO
ALTER TABLE [dbo].[ITEM_DEVOLUCAO] CHECK CONSTRAINT [FK_ITEM_DEVOLUCAO_DEVOLUCAO]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[TRANSACAO_PONTOS_FIDELIZA_FK1]') AND parent_object_id = OBJECT_ID(N'[dbo].[TRANSACAO_PONTOS]'))
ALTER TABLE [dbo].[TRANSACAO_PONTOS]  WITH CHECK ADD  CONSTRAINT [TRANSACAO_PONTOS_FIDELIZA_FK1] FOREIGN KEY([FID_ID])
REFERENCES [dbo].[FIDELIZACAO] ([FID_ID])
GO
ALTER TABLE [dbo].[TRANSACAO_PONTOS] CHECK CONSTRAINT [TRANSACAO_PONTOS_FIDELIZA_FK1]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[TRANSACAO_PONTOS_TRANSACA_FK1]') AND parent_object_id = OBJECT_ID(N'[dbo].[TRANSACAO_PONTOS]'))
ALTER TABLE [dbo].[TRANSACAO_PONTOS]  WITH CHECK ADD  CONSTRAINT [TRANSACAO_PONTOS_TRANSACA_FK1] FOREIGN KEY([LOJCOD], [TRNDAT], [CXANUM], [TRNSEQ])
REFERENCES [dbo].[TRANSACAO] ([LOJCOD], [TRNDAT], [CXANUM], [TRNSEQ])
GO
ALTER TABLE [dbo].[TRANSACAO_PONTOS] CHECK CONSTRAINT [TRANSACAO_PONTOS_TRANSACA_FK1]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_CLIENTE_LOJA]') AND parent_object_id = OBJECT_ID(N'[dbo].[CLIENTE]'))
ALTER TABLE [dbo].[CLIENTE]  WITH CHECK ADD  CONSTRAINT [FK_CLIENTE_LOJA] FOREIGN KEY([LOJCOD])
REFERENCES [dbo].[LOJA] ([LOJCOD])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[CLIENTE] CHECK CONSTRAINT [FK_CLIENTE_LOJA]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_CLIENTE_RAMO]') AND parent_object_id = OBJECT_ID(N'[dbo].[CLIENTE]'))
ALTER TABLE [dbo].[CLIENTE]  WITH CHECK ADD  CONSTRAINT [FK_CLIENTE_RAMO] FOREIGN KEY([RAMCOD])
REFERENCES [dbo].[RAMO] ([RAMCOD])
GO
ALTER TABLE [dbo].[CLIENTE] CHECK CONSTRAINT [FK_CLIENTE_RAMO]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_CLIENTE_REFERENCE_STATUS]') AND parent_object_id = OBJECT_ID(N'[dbo].[CLIENTE]'))
ALTER TABLE [dbo].[CLIENTE]  WITH CHECK ADD  CONSTRAINT [FK_CLIENTE_REFERENCE_STATUS] FOREIGN KEY([STACOD])
REFERENCES [dbo].[STATUS] ([STACOD])
GO
ALTER TABLE [dbo].[CLIENTE] CHECK CONSTRAINT [FK_CLIENTE_REFERENCE_STATUS]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_CAMPOS_PESQUISA_TABELA]') AND parent_object_id = OBJECT_ID(N'[dbo].[CAMPOS_PESQUISA]'))
ALTER TABLE [dbo].[CAMPOS_PESQUISA]  WITH CHECK ADD  CONSTRAINT [FK_CAMPOS_PESQUISA_TABELA] FOREIGN KEY([TBLCOD])
REFERENCES [dbo].[TABELA] ([TBLCOD])
GO
ALTER TABLE [dbo].[CAMPOS_PESQUISA] CHECK CONSTRAINT [FK_CAMPOS_PESQUISA_TABELA]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_FINALIZADORA_TIPO_DOCUMENTO]') AND parent_object_id = OBJECT_ID(N'[dbo].[FINALIZADORA]'))
ALTER TABLE [dbo].[FINALIZADORA]  WITH CHECK ADD  CONSTRAINT [FK_FINALIZADORA_TIPO_DOCUMENTO] FOREIGN KEY([TPDCOD])
REFERENCES [dbo].[TIPO_DOCUMENTO] ([TPDCOD])
GO
ALTER TABLE [dbo].[FINALIZADORA] CHECK CONSTRAINT [FK_FINALIZADORA_TIPO_DOCUMENTO]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ACESSO_GRUPOU_SUARIO]') AND parent_object_id = OBJECT_ID(N'[dbo].[ACESSO]'))
ALTER TABLE [dbo].[ACESSO]  WITH CHECK ADD  CONSTRAINT [FK_ACESSO_GRUPOU_SUARIO] FOREIGN KEY([GRPCOD])
REFERENCES [dbo].[GRUPO_USUARIO] ([GRPCOD])
GO
ALTER TABLE [dbo].[ACESSO] CHECK CONSTRAINT [FK_ACESSO_GRUPOU_SUARIO]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ACESSO_MENU]') AND parent_object_id = OBJECT_ID(N'[dbo].[ACESSO]'))
ALTER TABLE [dbo].[ACESSO]  WITH CHECK ADD  CONSTRAINT [FK_ACESSO_MENU] FOREIGN KEY([MEN_ID])
REFERENCES [dbo].[MENU] ([MEN_ID])
GO
ALTER TABLE [dbo].[ACESSO] CHECK CONSTRAINT [FK_ACESSO_MENU]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_PARTICIPANTES_GRUPO_USUARIO]') AND parent_object_id = OBJECT_ID(N'[dbo].[PARTICIPANTES]'))
ALTER TABLE [dbo].[PARTICIPANTES]  WITH CHECK ADD  CONSTRAINT [FK_PARTICIPANTES_GRUPO_USUARIO] FOREIGN KEY([GRPCOD])
REFERENCES [dbo].[GRUPO_USUARIO] ([GRPCOD])
GO
ALTER TABLE [dbo].[PARTICIPANTES] CHECK CONSTRAINT [FK_PARTICIPANTES_GRUPO_USUARIO]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_PARTICIPANTES_USUARIO]') AND parent_object_id = OBJECT_ID(N'[dbo].[PARTICIPANTES]'))
ALTER TABLE [dbo].[PARTICIPANTES]  WITH CHECK ADD  CONSTRAINT [FK_PARTICIPANTES_USUARIO] FOREIGN KEY([FUNCOD])
REFERENCES [dbo].[USUARIO] ([FUNCOD])
GO
ALTER TABLE [dbo].[PARTICIPANTES] CHECK CONSTRAINT [FK_PARTICIPANTES_USUARIO]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_LOJA_HOLDING]') AND parent_object_id = OBJECT_ID(N'[dbo].[LOJA]'))
ALTER TABLE [dbo].[LOJA]  WITH CHECK ADD  CONSTRAINT [FK_LOJA_HOLDING] FOREIGN KEY([HOLCOD])
REFERENCES [dbo].[HOLDING] ([HOLCOD])
GO
ALTER TABLE [dbo].[LOJA] CHECK CONSTRAINT [FK_LOJA_HOLDING]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ITEM_VENDA_LOJA]') AND parent_object_id = OBJECT_ID(N'[dbo].[ITEM_VENDA]'))
ALTER TABLE [dbo].[ITEM_VENDA]  WITH CHECK ADD  CONSTRAINT [FK_ITEM_VENDA_LOJA] FOREIGN KEY([LOJCOD])
REFERENCES [dbo].[LOJA] ([LOJCOD])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[ITEM_VENDA] CHECK CONSTRAINT [FK_ITEM_VENDA_LOJA]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ITEM_VENDA_TRANSACAO]') AND parent_object_id = OBJECT_ID(N'[dbo].[ITEM_VENDA]'))
ALTER TABLE [dbo].[ITEM_VENDA]  WITH CHECK ADD  CONSTRAINT [FK_ITEM_VENDA_TRANSACAO] FOREIGN KEY([LOJCOD], [TRNDAT], [CXANUM], [TRNSEQ])
REFERENCES [dbo].[TRANSACAO] ([LOJCOD], [TRNDAT], [CXANUM], [TRNSEQ])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[ITEM_VENDA] CHECK CONSTRAINT [FK_ITEM_VENDA_TRANSACAO]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ITEM_RECEBIMENTO_LOJA]') AND parent_object_id = OBJECT_ID(N'[dbo].[ITEM_RECEBIMENTO]'))
ALTER TABLE [dbo].[ITEM_RECEBIMENTO]  WITH CHECK ADD  CONSTRAINT [FK_ITEM_RECEBIMENTO_LOJA] FOREIGN KEY([LOJCOD])
REFERENCES [dbo].[LOJA] ([LOJCOD])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[ITEM_RECEBIMENTO] CHECK CONSTRAINT [FK_ITEM_RECEBIMENTO_LOJA]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ITEM_RECEBIMENTO_TRANSACAO]') AND parent_object_id = OBJECT_ID(N'[dbo].[ITEM_RECEBIMENTO]'))
ALTER TABLE [dbo].[ITEM_RECEBIMENTO]  WITH CHECK ADD  CONSTRAINT [FK_ITEM_RECEBIMENTO_TRANSACAO] FOREIGN KEY([LOJCOD], [TRNDAT], [CXANUM], [TRNSEQ])
REFERENCES [dbo].[TRANSACAO] ([LOJCOD], [TRNDAT], [CXANUM], [TRNSEQ])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[ITEM_RECEBIMENTO] CHECK CONSTRAINT [FK_ITEM_RECEBIMENTO_TRANSACAO]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ITEM_PAGAMENTO_TRANSACAO]') AND parent_object_id = OBJECT_ID(N'[dbo].[ITEM_PAGAMENTO]'))
ALTER TABLE [dbo].[ITEM_PAGAMENTO]  WITH CHECK ADD  CONSTRAINT [FK_ITEM_PAGAMENTO_TRANSACAO] FOREIGN KEY([LOJCOD], [TRNDAT], [CXANUM], [TRNSEQ])
REFERENCES [dbo].[TRANSACAO] ([LOJCOD], [TRNDAT], [CXANUM], [TRNSEQ])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[ITEM_PAGAMENTO] CHECK CONSTRAINT [FK_ITEM_PAGAMENTO_TRANSACAO]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[ITEM_PAGAMENTO_LOJA_FK1]') AND parent_object_id = OBJECT_ID(N'[dbo].[ITEM_PAGAMENTO]'))
ALTER TABLE [dbo].[ITEM_PAGAMENTO]  WITH CHECK ADD  CONSTRAINT [ITEM_PAGAMENTO_LOJA_FK1] FOREIGN KEY([LOJCOD])
REFERENCES [dbo].[LOJA] ([LOJCOD])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[ITEM_PAGAMENTO] CHECK CONSTRAINT [ITEM_PAGAMENTO_LOJA_FK1]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ITEM_PLANO_PAG_TRANSACAO]') AND parent_object_id = OBJECT_ID(N'[dbo].[ITEM_PLANO_PAGAMENTO]'))
ALTER TABLE [dbo].[ITEM_PLANO_PAGAMENTO]  WITH CHECK ADD  CONSTRAINT [FK_ITEM_PLANO_PAG_TRANSACAO] FOREIGN KEY([LOJCOD], [TRNDAT], [CXANUM], [TRNSEQ])
REFERENCES [dbo].[TRANSACAO] ([LOJCOD], [TRNDAT], [CXANUM], [TRNSEQ])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[ITEM_PLANO_PAGAMENTO] CHECK CONSTRAINT [FK_ITEM_PLANO_PAG_TRANSACAO]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[ITEM_PLANO_PAGAMENTO_LOJA_FK1]') AND parent_object_id = OBJECT_ID(N'[dbo].[ITEM_PLANO_PAGAMENTO]'))
ALTER TABLE [dbo].[ITEM_PLANO_PAGAMENTO]  WITH CHECK ADD  CONSTRAINT [ITEM_PLANO_PAGAMENTO_LOJA_FK1] FOREIGN KEY([LOJCOD])
REFERENCES [dbo].[LOJA] ([LOJCOD])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[ITEM_PLANO_PAGAMENTO] CHECK CONSTRAINT [ITEM_PLANO_PAGAMENTO_LOJA_FK1]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_REDUCAO_LOJA]') AND parent_object_id = OBJECT_ID(N'[dbo].[REDUCAO]'))
ALTER TABLE [dbo].[REDUCAO]  WITH CHECK ADD  CONSTRAINT [FK_REDUCAO_LOJA] FOREIGN KEY([LOJCOD])
REFERENCES [dbo].[LOJA] ([LOJCOD])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[REDUCAO] CHECK CONSTRAINT [FK_REDUCAO_LOJA]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_REDUCAO_TRANSACAO]') AND parent_object_id = OBJECT_ID(N'[dbo].[REDUCAO]'))
ALTER TABLE [dbo].[REDUCAO]  WITH CHECK ADD  CONSTRAINT [FK_REDUCAO_TRANSACAO] FOREIGN KEY([LOJCOD], [TRNDAT], [CXANUM], [TRNSEQ])
REFERENCES [dbo].[TRANSACAO] ([LOJCOD], [TRNDAT], [CXANUM], [TRNSEQ])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[REDUCAO] CHECK CONSTRAINT [FK_REDUCAO_TRANSACAO]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[CONSUMIDOR_MOVIMENTACAO_TRAN]') AND parent_object_id = OBJECT_ID(N'[dbo].[CONSUMIDOR_MOVIMENTACAO]'))
ALTER TABLE [dbo].[CONSUMIDOR_MOVIMENTACAO]  WITH CHECK ADD  CONSTRAINT [CONSUMIDOR_MOVIMENTACAO_TRAN] FOREIGN KEY([LOJCOD], [TRNDAT], [CXANUM], [TRNSEQ])
REFERENCES [dbo].[TRANSACAO] ([LOJCOD], [TRNDAT], [CXANUM], [TRNSEQ])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[CONSUMIDOR_MOVIMENTACAO] CHECK CONSTRAINT [CONSUMIDOR_MOVIMENTACAO_TRAN]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_CONS_MOVIMENTACAO_LOJA]') AND parent_object_id = OBJECT_ID(N'[dbo].[CONSUMIDOR_MOVIMENTACAO]'))
ALTER TABLE [dbo].[CONSUMIDOR_MOVIMENTACAO]  WITH CHECK ADD  CONSTRAINT [FK_CONS_MOVIMENTACAO_LOJA] FOREIGN KEY([LOJCOD])
REFERENCES [dbo].[LOJA] ([LOJCOD])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[CONSUMIDOR_MOVIMENTACAO] CHECK CONSTRAINT [FK_CONS_MOVIMENTACAO_LOJA]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_IMPOSTOS_FEDERAIS_IMPFED]') AND parent_object_id = OBJECT_ID(N'[dbo].[IMPOSTOS_FEDERAIS_PRODUTO]'))
ALTER TABLE [dbo].[IMPOSTOS_FEDERAIS_PRODUTO]  WITH CHECK ADD  CONSTRAINT [FK_IMPOSTOS_FEDERAIS_IMPFED] FOREIGN KEY([IMPFEDID])
REFERENCES [dbo].[IMPOSTOS_FEDERAIS] ([IMPFEDID])
GO
ALTER TABLE [dbo].[IMPOSTOS_FEDERAIS_PRODUTO] CHECK CONSTRAINT [FK_IMPOSTOS_FEDERAIS_IMPFED]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_PRODUTO_IMPFED]') AND parent_object_id = OBJECT_ID(N'[dbo].[IMPOSTOS_FEDERAIS_PRODUTO]'))
ALTER TABLE [dbo].[IMPOSTOS_FEDERAIS_PRODUTO]  WITH CHECK ADD  CONSTRAINT [FK_PRODUTO_IMPFED] FOREIGN KEY([PROID])
REFERENCES [dbo].[PRODUTO] ([PRODID])
GO
ALTER TABLE [dbo].[IMPOSTOS_FEDERAIS_PRODUTO] CHECK CONSTRAINT [FK_PRODUTO_IMPFED]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TRC_PREM_TRC_PREM_RET]') AND parent_object_id = OBJECT_ID(N'[dbo].[TROCO_PREMIADO]'))
ALTER TABLE [dbo].[TROCO_PREMIADO]  WITH CHECK ADD  CONSTRAINT [FK_TRC_PREM_TRC_PREM_RET] FOREIGN KEY([TPTNUM])
REFERENCES [dbo].[TROCO_PREMIADO_RETORNO] ([TPTNUM])
GO
ALTER TABLE [dbo].[TROCO_PREMIADO] CHECK CONSTRAINT [FK_TRC_PREM_TRC_PREM_RET]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TROCO_PREMIADO_REMESSA]') AND parent_object_id = OBJECT_ID(N'[dbo].[TROCO_PREMIADO]'))
ALTER TABLE [dbo].[TROCO_PREMIADO]  WITH CHECK ADD  CONSTRAINT [FK_TROCO_PREMIADO_REMESSA] FOREIGN KEY([TPRNUMREM])
REFERENCES [dbo].[TROCO_PREMIADO_REMESSA] ([TPRNUMREM])
GO
ALTER TABLE [dbo].[TROCO_PREMIADO] CHECK CONSTRAINT [FK_TROCO_PREMIADO_REMESSA]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_PRECO_LOJA]') AND parent_object_id = OBJECT_ID(N'[dbo].[PRECO]'))
ALTER TABLE [dbo].[PRECO]  WITH CHECK ADD  CONSTRAINT [FK_PRECO_LOJA] FOREIGN KEY([LOJCOD])
REFERENCES [dbo].[LOJA] ([LOJCOD])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[PRECO] CHECK CONSTRAINT [FK_PRECO_LOJA]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_PREFINALIZACAO_LOJA]') AND parent_object_id = OBJECT_ID(N'[dbo].[PREFINALIZACAO]'))
ALTER TABLE [dbo].[PREFINALIZACAO]  WITH CHECK ADD  CONSTRAINT [FK_PREFINALIZACAO_LOJA] FOREIGN KEY([LOJCOD])
REFERENCES [dbo].[LOJA] ([LOJCOD])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[PREFINALIZACAO] CHECK CONSTRAINT [FK_PREFINALIZACAO_LOJA]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_PREVENDA_LOJA]') AND parent_object_id = OBJECT_ID(N'[dbo].[PREVENDA]'))
ALTER TABLE [dbo].[PREVENDA]  WITH CHECK ADD  CONSTRAINT [FK_PREVENDA_LOJA] FOREIGN KEY([LOJCOD])
REFERENCES [dbo].[LOJA] ([LOJCOD])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[PREVENDA] CHECK CONSTRAINT [FK_PREVENDA_LOJA]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[MOVIMENTO_PREMIO_LOJA_FK1]') AND parent_object_id = OBJECT_ID(N'[dbo].[MOVIMENTO_PREMIO]'))
ALTER TABLE [dbo].[MOVIMENTO_PREMIO]  WITH CHECK ADD  CONSTRAINT [MOVIMENTO_PREMIO_LOJA_FK1] FOREIGN KEY([LOJCOD])
REFERENCES [dbo].[LOJA] ([LOJCOD])
GO
ALTER TABLE [dbo].[MOVIMENTO_PREMIO] CHECK CONSTRAINT [MOVIMENTO_PREMIO_LOJA_FK1]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[MOVIMENTO_PREMIO_PREMIO_FK1]') AND parent_object_id = OBJECT_ID(N'[dbo].[MOVIMENTO_PREMIO]'))
ALTER TABLE [dbo].[MOVIMENTO_PREMIO]  WITH CHECK ADD  CONSTRAINT [MOVIMENTO_PREMIO_PREMIO_FK1] FOREIGN KEY([PRE_ID])
REFERENCES [dbo].[PREMIO] ([PRE_ID])
GO
ALTER TABLE [dbo].[MOVIMENTO_PREMIO] CHECK CONSTRAINT [MOVIMENTO_PREMIO_PREMIO_FK1]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_LOCAL_LOJA]') AND parent_object_id = OBJECT_ID(N'[dbo].[LOCAL]'))
ALTER TABLE [dbo].[LOCAL]  WITH CHECK ADD  CONSTRAINT [FK_LOCAL_LOJA] FOREIGN KEY([LOJCOD])
REFERENCES [dbo].[LOJA] ([LOJCOD])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[LOCAL] CHECK CONSTRAINT [FK_LOCAL_LOJA]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[ITEM_PREVENDA_LOJA_FK1]') AND parent_object_id = OBJECT_ID(N'[dbo].[ITEM_PREVENDA]'))
ALTER TABLE [dbo].[ITEM_PREVENDA]  WITH CHECK ADD  CONSTRAINT [ITEM_PREVENDA_LOJA_FK1] FOREIGN KEY([PRVNUM])
REFERENCES [dbo].[LOJA] ([LOJCOD])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[ITEM_PREVENDA] CHECK CONSTRAINT [ITEM_PREVENDA_LOJA_FK1]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_FUNCIONARIO_LOJA]') AND parent_object_id = OBJECT_ID(N'[dbo].[FUNCIONARIO]'))
ALTER TABLE [dbo].[FUNCIONARIO]  WITH CHECK ADD  CONSTRAINT [FK_FUNCIONARIO_LOJA] FOREIGN KEY([LOJCOD])
REFERENCES [dbo].[LOJA] ([LOJCOD])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[FUNCIONARIO] CHECK CONSTRAINT [FK_FUNCIONARIO_LOJA]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_FILA_LOJA]') AND parent_object_id = OBJECT_ID(N'[dbo].[FILA_SINCRONIZACAO]'))
ALTER TABLE [dbo].[FILA_SINCRONIZACAO]  WITH CHECK ADD  CONSTRAINT [FK_FILA_LOJA] FOREIGN KEY([LOJA])
REFERENCES [dbo].[LOJA] ([LOJCOD])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[FILA_SINCRONIZACAO] CHECK CONSTRAINT [FK_FILA_LOJA]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_URL_MENU]') AND parent_object_id = OBJECT_ID(N'[dbo].[URL]'))
ALTER TABLE [dbo].[URL]  WITH CHECK ADD  CONSTRAINT [FK_URL_MENU] FOREIGN KEY([MEN_ID])
REFERENCES [dbo].[MENU] ([MEN_ID])
GO
ALTER TABLE [dbo].[URL] CHECK CONSTRAINT [FK_URL_MENU]
GO
Insert into HOLDING (HOLCOD,HOLDES) values (1,'GERAL');
GO
Insert into LOJA (LOJCOD,HOLCOD) values (1,1);
GO
Insert into FUNCIONARIO (FUNCOD,FUNAPE,FUNBAI,FUNCAR,FUNCEL,FUNCEP,FUNCID,FUNCOMP,FUNCPF,FUNDTNAS,FUNEMA,FUNEND,FUNRAM,FUNTEL,FUNTEL2,FUNUF,LOJCOD) values (1,'SYSPDV','FUNBAI','FUNCAR','FUNCEL','FUNCEP','FUNCID','FUNCOMP','FUNCPF','FUNDTNAS','FUNEMA','FUNEND','FUNRAM','FUNTEL','FUNTEL2','CE',1);
GO
Insert into USUARIO (FUNCOD,USUNOM,USUSEN) values (1,'syspdv','c2acebdee6926cb3556c4f75787c4894');
GO
INSERT INTO  GRUPO_USUARIO (GRPCOD,GRPATIV,GRPNOM,GRPWEBSERVER) values (0,'INATIVO','FUNCIONÁRIO(PADRÃO)', 1);
INSERT INTO  GRUPO_USUARIO (GRPCOD,GRPATIV,GRPNOM,GRPWEBSERVER) values (1,'ATIVO','ADMINISTRACAO', 1);
INSERT INTO  GRUPO_USUARIO (GRPCOD,GRPATIV,GRPNOM,GRPWEBSERVER) values (3,'ATIVO','grupo', 1);
GO
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (1,0,'Sistema',null,null,null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (5,0,'Loja',null,null,null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (8,0,'Cliente',null,null,null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (17,0,'Produto',null,null,null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (21,0,'PDV',null,null,null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (24,0,'Pessoal',null,null,null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (33,0,'Consulta',null,null,null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (52,0,'Integração',null,null,null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (62,0,'Relatórios',null,null,null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (3,1,'Acesso',null,'acessoForm.cm',null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (4,1,'Configuração',null,'configuracaoForm.cm','CONFIGURACAO');
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (2,1,'Parâmetro',null,'parametroForm.cm','PARAMETRO');
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (6,5,'Loja',null,'lojaForm.cm','LOJA');
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (7,5,'Holding',null,'holdingForm.cm','HOLDING');
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (9,8,'Cliente',null,'clienteForm.cm','CLIENTE');
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (10,8,'Limite de Crédito',null,null,null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (13,8,'Status',null,'statusForm.cm','STATUS');
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (14,8,'Alterar Status',null,'alteraStatusForm.cm','ALTERARSTATUS');
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (15,8,'Ramo',null,'ramoForm.cm','RAMO');
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (16,8,'Cadastro de Senha',null,'clienteSenhaForm.cm','CLIENTESENHA');
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (55,8,'Fidelização',null,null,null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (63,8,'Autorizador',null,null,null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (41,17,'Produto',null,'produto/produto.cm','PRODUTO');
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (42,17,'Reajuste',null,null,null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (43,17,'Classificação',null,null,null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (44,17,'Unidade',null,'unidadeProdutoForm.cm','UNIDADE');
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (45,17,'Impostos',null,null,null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (22,21,'Finalizadora',null,'finalizadoraForm.cm','FINALIZADORA');
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (23,21,'Tipo de Documento',null,'tipoDocumentoForm.cm','TIPODOCUMENTO');
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (25,24,'Funcionário',null,'funcionarioForm.cm','FUNCIONARIO');
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (26,24,'Grupo de Usuário',null,null,null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (29,24,'Usuário',null,'usuarioForm.cm','USUARIO');
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (51,33,'Estoque',null,'estoque/consulta.cm',null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (32,33,'Estatisticas de venda',null,'estatisticas/','ESTATISTICAS');
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (66,52,'Importação',null,null,null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (67,52,'Exportação',null,null,null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (68,52,'Sincronização',null,'/SysPDVWebSynch/sincronizacao',null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (11,10,'Limite de Crédito',null,'limiteCreditoForm.cm','LIMITECREDITO');
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (12,10,'Autorização',null,'autorizacaoForm.cm','AUTORIZACAO');
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (69,55,'Premios',null,null,null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (56,69,'Cadastro',null,'/SysPDVWebFidelizacao/premio/cadastro',null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (70,69,'Resgate',null,'/SysPDVWebFidelizacao/premio/resgate',null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (71,69,'Estorno',null,'/SysPDVWebFidelizacao/premio/estorno',null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (72,55,'Cartão',null,null,null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (57,72,'Gerar Cartão',null,'/SysPDVWebFidelizacao/gerarCartaoFidelizacao',null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (58,72,'Consultar Cartão',null,'/SysPDVWebFidelizacao/consultarCartaoFidelizacao',null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (73,55,'Relatórios',null,null,null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (74,73,'Extrato',null,'/SysPDVWebFidelizacao/relatorio/extratoDePontos',null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (75,73,'Cartões',null,'/SysPDVWebFidelizacao/relatorio/cartoesPorStatus',null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (76,73,'Clientes Inativo',null,'/SysPDVWebFidelizacao/relatorio/clientesInativos',null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (77,73,'Hábitos de Consumo',null,'/SysPDVWebFidelizacao/relatorio/habitoDeConsumo',null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (78,73,'Cliente em Potêncial',null,'/SysPDVWebFidelizacao/relatorio/clientesEmPotencial',null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (48,42,'Preço',null,'reajuste/preco.cm','PRECO');
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (18,43,'Seção',null,'secaoForm.cm','SECAO');
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (19,43,'Grupo',null,'grupoProdutoForm.cm','GRUPOPRODUTO');
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (20,43,'SubGrupo',null,'subGrupoProdutoForm.cm','SUBGRUPOPRODUTO');
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (46,45,'Impostos Federais',null,'impostosFederaisForm.cm','IMPOSTOSFEDERAIS');
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (27,26,'Grupo de Usuários',null,'grupoUsuarioForm.cm','GRUPOUSUARIO');
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (28,26,'Atribuição',null,'participanteForm.cm','PARTICIPANTE');
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (30,29,'Cadastro de Senha',null,'usuarioForm.cm','USUARIOSENHA');
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (36,62,'Cliente',null,'reportCliente.cm','RELATORIOCLIENTE');
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (37,62,'Funcionário',null,'reportFuncionario.cm','RELATORIOFUNCIONARIO');
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (39,62,'Limite de Crédito',null,'reportLimiteDeCredito.cm',null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (54,62,'Ecf',null,'reportEcf.cm',null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (59,62,'Troco Premiado',null,'reportTrocoPremiado.cm',null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (61,62,'Pré-Pago',null,'reportPrePagoPorOperadora.cm',null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (88,62,'Estoque',null,'reportEstoque.cm',null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (79,63,'Situação',null,'/SysPDVWebAutorizador/cartao/situacao/form',null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (80,63,'Monitoramento',null,'/SysPDVWebAutorizador/monitoramento/form',null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (81,63,'Extrato',null,'/SysPDVWebAutorizador/cartao/extrato/form',null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (82,63,'Relatórios',null,'/SysPDVWebAutorizador/relatorio/form',null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (83,66,'Cadastro',null,'/SysPDVWebSynch/importacao/cadastro',null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (84,66,'Troco Premiado',null,'/SysPDVWebSynch/importacao/trocopremiado',null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (85,66,'Cep',null,'/SysPDVWebSynch/importacao/cep',null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (86,67,'Movimentação',null,'/SysPDVWebSynch/exportacao/movimentacao',null);
Insert into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (87,67,'Troco Premiado',null,'/SysPDVWebSynch/exportacao/trocopremiado',null);
GO
Insert into TABELA (TBLCOD,TBLCLS,TBLDES) values (44,'ImpostosFederais','IMPOSTOS_FEDERAIS');
Insert into TABELA (TBLCOD,TBLCLS,TBLDES) values (33,'SubGrupoProduto','SUBGRUPO_PRODUTO');
Insert into TABELA (TBLCOD,TBLCLS,TBLDES) values (8,'Parametro','PARAMETRO');
Insert into TABELA (TBLCOD,TBLCLS,TBLDES) values (9,'Finalizadora','FINALIZADORA');
Insert into TABELA (TBLCOD,TBLCLS,TBLDES) values (10,'TipoDocumento','TIPO_DOCUMENTO');
Insert into TABELA (TBLCOD,TBLCLS,TBLDES) values (1,'Cliente','CLIENTE');
Insert into TABELA (TBLCOD,TBLCLS,TBLDES) values (2,'Loja','LOJA');
Insert into TABELA (TBLCOD,TBLCLS,TBLDES) values (3,'Holding','HOLDING');
Insert into TABELA (TBLCOD,TBLCLS,TBLDES) values (5,'Autorizacao','AUTORIZACAO');
Insert into TABELA (TBLCOD,TBLCLS,TBLDES) values (6,'Status','STATUS');
Insert into TABELA (TBLCOD,TBLCLS,TBLDES) values (7,'Ramo','RAMO');
Insert into TABELA (TBLCOD,TBLCLS,TBLDES) values (11,'Funcionario','FUNCIONARIO');
Insert into TABELA (TBLCOD,TBLCLS,TBLDES) values (12,'GrupoUsuario','GRUPO_USUARIO');
Insert into TABELA (TBLCOD,TBLCLS,TBLDES) values (13,'Usuario','USUARIO');
Insert into TABELA (TBLCOD,TBLCLS,TBLDES) values (14,'TrocoPremiadoRetorno','TROCO_PREMIADO_RETORNO');
Insert into TABELA (TBLCOD,TBLCLS,TBLDES) values (15,'Proprio','PROPRIO');
Insert into TABELA (TBLCOD,TBLCLS,TBLDES) values (43,'GrupoProduto','GRUPOPRODUTO');
Insert into TABELA (TBLCOD,TBLCLS,TBLDES) values (46,'Fornecedor','FORNECEDOR');
Insert into TABELA (TBLCOD,TBLCLS,TBLDES) values (31,'Secao','SECAO');
Insert into TABELA (TBLCOD,TBLCLS,TBLDES) values (45,'Tributacao','TRIBUTACAO');
Insert into TABELA (TBLCOD,TBLCLS,TBLDES) values (42,'Produto','PRODUTO');
Insert into TABELA (TBLCOD,TBLCLS,TBLDES) values (41,'UnidadeProduto','UNIDADE');
GO
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('codigo',15,'PRPCOD',50,'Código',1,'A','java.lang.Integer');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('descricao',15,'PRPDES',100,'Descrição',2,'A','java.lang.String');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('codigo',43,'GRPCOD',100,'Código',2,'A','java.lang.String');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('codigo',42,'PROCOD',50,'Código',1,'A','java.lang.Long');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('descricao',42,'PRODES',100,'Descrição',2,'A','java.lang.String');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('descricao',43,'GRPDES',100,'Descrição',1,'A','java.lang.String');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('codigo',1,'CLICOD',50,'Código',1,'A','java.lang.Long');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('descricao',1,'CLIDES',200,'Nome/Razão Social',2,'A','java.lang.String');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('cpfcgc',1,'CLICPFCGC',100,'CPF/CPNJ',3,'A','java.lang.String');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('endereco',1,'CLIEND',100,'Endereço',4,'C','java.lang.String');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('nomeFantasia',1,'CLIFAN',150,'Nome Fantasia',5,'A','java.lang.String');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('telefone',1,'CLITEL',80,'Telefone',6,'G','java.lang.String');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('codigo',11,'FUNCOD',50,'Código',1,'A','java.lang.Integer');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('nome',11,'FUNNOM',100,'Descrição',2,'A','java.lang.String');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('ativo',12,'GRPATIV',80,'Ativo',3,'G','java.lang.String');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('codigo',12,'GRPCOD',50,'Código',1,'A','java.lang.Integer');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('nome',12,'GRPNOM',100,'Nome',2,'A','java.lang.String');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('codigo',3,'HOLCOD',50,'Código',1,'A','java.lang.Integer');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('descricao',3,'HOLDES',100,'Descrição',2,'A','java.lang.String');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('codigo',7,'RAMCOD',50,'Código',1,'A','java.lang.Integer');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('descricao',7,'RAMDES',100,'Descrição',2,'A','java.lang.String');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('codigo',6,'STACOD',50,'Código',1,'A','java.lang.Integer');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('descricao',6,'STADES',100,'Descrição',2,'A','java.lang.String');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('bloqueado',6,'STABLC',80,'Bloqueado',3,'A','java.lang.String');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('codigo',10,'TPDCOD',50,'Código',1,'A','java.lang.Integer');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('descricao',10,'TPDDES',100,'Descrição',2,'A','java.lang.String');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('codigo',13,'FUNCOD',50,'Código',1,'A','java.lang.Integer');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('login',13,'USUNOM',100,'Login',2,'A','java.lang.String');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('codigo',8,'PARCOD',50,'Código',1,'A','java.lang.Integer');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('critica',8,'PARCRITICA',100,'Crítica',4,'A','java.lang.String');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('descricao',8,'PARDES',200,'Descrição',2,'A','java.lang.String');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('observacao',8,'PAROBS',500,'Observação',5,'A','java.lang.String');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('validacao',8,'PARVALID',60,'Validação',3,'A','java.lang.String');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('codigo',2,'LOJCOD',50,'Código',1,'A','java.lang.Integer');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('nome',2,'LOJDES',100,'Descrição',2,'A','java.lang.String');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('codigo',9,'FZDCOD',50,'Código',1,'A','java.lang.Integer');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('descricao',9,'FZDDES',100,'Descrição',2,'A','java.lang.String');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('codigoAutorizacao',5,'AUTCOD',50,'Código',1,'A','java.lang.Integer');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('dataAutorizacao',5,'AUTDAT',50,'Data',4,'A','java.util.Date');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('descricao',5,'AUTDESC',50,'Descrição',2,'A','java.lang.String');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('numeroCaixa',5,'AUTCXANUM',100,'Número Caixa',3,'A','java.lang.Integer');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('codigo',14,'TPTNUM',50,'Código',1,'A','java.lang.Integer');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('dataExportacao',14,'TPTDAT',100,'Data',2,'A','java.util.Date');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('codigo',45,'TRBCOD',50,'Código',1,'A','java.lang.String');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('descricao',45,'TRBDES',100,'Descrição',2,'A','java.lang.String');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('descricao',44,'IMPFEDDES',100,'Descrição',2,'A','java.lang.String');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('codigo',46,'FORCOD',50,'Código',1,'A','java.lang.Integer');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('descricao',46,'FORDES',100,'Descrição',2,'A','java.lang.String');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('codigo',33,'SGPCOD',30,'Código',1,'G','java.lang.Integer');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('descricao',33,'SGPDES',100,'Descrição',2,'A','java.lang.String');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('sigla',44,'IMPFEDSIM',30,'Sigla',1,'G','java.lang.String');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('codigo',41,'UNDCOD',100,'Código',1,'A','java.lang.String');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('descricao',41,'UNDDES',100,'Descrição',2,'A','java.lang.String');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('codigo',31,'SECCOD',30,'Código',1,'G','java.lang.Integer');
INSERT	 into CAMPOS_PESQUISA (CMPCLSATB,TBLCOD,CMPATB,CMPWID,CMPDESCATB,CMPORD,CMPSTA,CMPCLSTIPO) values ('descricao',31,'SECDES',100,'Descrição',2,'A','java.lang.String');
GO

INSERT into PARTICIPANTES (FUNCOD,GRPCOD) values (1,0)
INSERT into PARTICIPANTES (FUNCOD,GRPCOD) values (1,1)
GO
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,51);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,52);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,3);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,4);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,5);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,6);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,7);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,8);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,9);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,10);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,11);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,12);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,13);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,14);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,15);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,16);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,17);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,18);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,19);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,20);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,21);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,22);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,23);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,24);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,25);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,26);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,27);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,28);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,29);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,30);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,32);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,33);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,36);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,37);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,39);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,41);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,42);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,43);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,44);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,45);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,46);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,48);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,1);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,2);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,54);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,55);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,56);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,57);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,58);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,59);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,61);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,62);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,63);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,66);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,67);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,68);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,69);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,70);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,71);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,72);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,73);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,74);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,75);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,76);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,77);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,78);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,79);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,80);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,81);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,82);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,83);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,84);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,85);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,86);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,87);
Insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,88);
GO
Insert into PARAMETRO (PARCOD,PARCRITICA,PARDES,PAROBS,PARSTA,PARVALID) values (551,'s','Preço Nome 1','Varejo',null,'1');
Insert into PARAMETRO (PARCOD,PARCRITICA,PARDES,PAROBS,PARSTA,PARVALID) values (552,'s','Preço Nome 2','Tipo 2',null,'2');
Insert into PARAMETRO (PARCOD,PARCRITICA,PARDES,PAROBS,PARSTA,PARVALID) values (553,'s','Preço Nome 3','Tipo 3',null,'3');
Insert into PARAMETRO (PARCOD,PARCRITICA,PARDES,PAROBS,PARSTA,PARVALID) values (50,'123','Preço - opções de preço','1-Preço Único 2-Dois preços 3-Três preços',null,'3');
Insert into PARAMETRO (PARCOD,PARCRITICA,PARDES,PAROBS,PARSTA,PARVALID) values (1,'SN','parametro 1','Sim ou Nao',null,'N');
Insert into PARAMETRO (PARCOD,PARCRITICA,PARDES,PAROBS,PARSTA,PARVALID) values (500,'S','Caminho dos aquivos de carga','C:\Syspdv',null,'s');
Insert into PARAMETRO (PARCOD,PARCRITICA,PARDES,PAROBS,PARSTA,PARVALID) values (550,'s','Caminho dos aquivos de carga','C:\Syspdv',null,'s');
Insert into PARAMETRO (PARCOD,PARCRITICA,PARDES,PAROBS,PARSTA,PARVALID) values (505,'s','Caminho importação de Cadastros','C:\Syspdv\tx',null,null);
Insert into PARAMETRO (PARCOD,PARCRITICA,PARDES,PAROBS,PARSTA,PARVALID) values (601,null,'20','PERIODO EM MINUTOS PARA INTERVALO DE VENDA DE MESMO VALOR',null,null);
Insert into PARAMETRO (PARCOD,PARCRITICA,PARDES,PAROBS,PARSTA,PARVALID) values (602,null,'0.1','VALOR PERCENTUAL DA MARGEM DE CREDITO DE VENDA',null,null);
GO

INSERT	 into RAMO (RAMCOD,RAMDES) values (2,'MOVELEIRO');
INSERT	 into RAMO (RAMCOD,RAMDES) values (3,'COMERCIANTE');
INSERT	 into RAMO (RAMCOD,RAMDES) values (4,'PROGETISTA');
INSERT	 into RAMO (RAMCOD,RAMDES) values (5,'CONDOMINIO');
INSERT	 into RAMO (RAMCOD,RAMDES) values (6,'PINTURA');
INSERT	 into RAMO (RAMCOD,RAMDES) values (7,'OTICA');
INSERT	 into RAMO (RAMCOD,RAMDES) values (8,'CONSTRUTORA');
INSERT	 into RAMO (RAMCOD,RAMDES) values (9,'ESCOLA');
INSERT	 into RAMO (RAMCOD,RAMDES) values (0,'OUTROS');
INSERT	 into RAMO (RAMCOD,RAMDES) values (1,'MARCINEIRO');
INSERT	 into RAMO (RAMCOD,RAMDES) values (10,'FORNECEDOR');
INSERT	 into RAMO (RAMCOD,RAMDES) values (11,'ORGAO PUBLICO');
GO
Insert into STATUS (STACOD,STABLC,STADES,STATIPBLOQ,STA_ORIGEM_ALTERACAO,STA_DATA_ALTERACAO,STA_CHAVE_RETAGUARDA,STA_VERSAO_RETAGUARDA) values (63946215,1,'01 - Bloq. Ações Cob Atr 091/180 dias','1',null,null,null,null);
Insert into STATUS (STACOD,STABLC,STADES,STATIPBLOQ,STA_ORIGEM_ALTERACAO,STA_DATA_ALTERACAO,STA_CHAVE_RETAGUARDA,STA_VERSAO_RETAGUARDA) values (63946216,1,'02 - Bloq. Ações Cob Atr 181/270 dias','2',null,null,null,null);
Insert into STATUS (STACOD,STABLC,STADES,STATIPBLOQ,STA_ORIGEM_ALTERACAO,STA_DATA_ALTERACAO,STA_CHAVE_RETAGUARDA,STA_VERSAO_RETAGUARDA) values (63946217,1,'03 - Bloq. Ações Cob Atr 271/360 dias','3',null,null,null,null);
Insert into STATUS (STACOD,STABLC,STADES,STATIPBLOQ,STA_ORIGEM_ALTERACAO,STA_DATA_ALTERACAO,STA_CHAVE_RETAGUARDA,STA_VERSAO_RETAGUARDA) values (63946218,1,'04 - Bloq. Ações Cob Atr 361/450 dias','4',null,null,null,null);
Insert into STATUS (STACOD,STABLC,STADES,STATIPBLOQ,STA_ORIGEM_ALTERACAO,STA_DATA_ALTERACAO,STA_CHAVE_RETAGUARDA,STA_VERSAO_RETAGUARDA) values (63946219,1,'05 - Bloq. Ações Cob Atr 451/540 dias','5',null,null,null,null);
Insert into STATUS (STACOD,STABLC,STADES,STATIPBLOQ,STA_ORIGEM_ALTERACAO,STA_DATA_ALTERACAO,STA_CHAVE_RETAGUARDA,STA_VERSAO_RETAGUARDA) values (63946220,1,'06 - Bloq. Ações Cob Atr 541/630 dias','6',null,null,null,null);
Insert into STATUS (STACOD,STABLC,STADES,STATIPBLOQ,STA_ORIGEM_ALTERACAO,STA_DATA_ALTERACAO,STA_CHAVE_RETAGUARDA,STA_VERSAO_RETAGUARDA) values (63946222,1,'08 - Bloqueio por cadastro incompleto','8',null,null,null,null);
Insert into STATUS (STACOD,STABLC,STADES,STATIPBLOQ,STA_ORIGEM_ALTERACAO,STA_DATA_ALTERACAO,STA_CHAVE_RETAGUARDA,STA_VERSAO_RETAGUARDA) values (63946223,1,'09- Conta Cancelada á Pedido do Cliente','9',null,null,null,null);
Insert into STATUS (STACOD,STABLC,STADES,STATIPBLOQ,STA_ORIGEM_ALTERACAO,STA_DATA_ALTERACAO,STA_CHAVE_RETAGUARDA,STA_VERSAO_RETAGUARDA) values (63946224,1,'10- Bloqueio por Renegociação	','10',null,null,null,null);
Insert into STATUS (STACOD,STABLC,STADES,STATIPBLOQ,STA_ORIGEM_ALTERACAO,STA_DATA_ALTERACAO,STA_CHAVE_RETAGUARDA,STA_VERSAO_RETAGUARDA) values (63946225,1,'11- Bloqueio Pagamento Principal	','11',null,null,null,null);
Insert into STATUS (STACOD,STABLC,STADES,STATIPBLOQ,STA_ORIGEM_ALTERACAO,STA_DATA_ALTERACAO,STA_CHAVE_RETAGUARDA,STA_VERSAO_RETAGUARDA) values (63946226,1,'12- Bloqueio Desconto Principal','12',null,null,null,null);
Insert into STATUS (STACOD,STABLC,STADES,STATIPBLOQ,STA_ORIGEM_ALTERACAO,STA_DATA_ALTERACAO,STA_CHAVE_RETAGUARDA,STA_VERSAO_RETAGUARDA) values (63946227,1,'13 - Bloqueio Falecimento Titular','13',null,null,null,null);
Insert into STATUS (STACOD,STABLC,STADES,STATIPBLOQ,STA_ORIGEM_ALTERACAO,STA_DATA_ALTERACAO,STA_CHAVE_RETAGUARDA,STA_VERSAO_RETAGUARDA) values (63946228,1,'14 - Bloqueio por Débitos Incobráveis','14',null,null,null,null);
Insert into STATUS (STACOD,STABLC,STADES,STATIPBLOQ,STA_ORIGEM_ALTERACAO,STA_DATA_ALTERACAO,STA_CHAVE_RETAGUARDA,STA_VERSAO_RETAGUARDA) values (63946229,1,'15 - Bloqueio SPC/SERASA Terceiros','15',null,null,null,null);
Insert into STATUS (STACOD,STABLC,STADES,STATIPBLOQ,STA_ORIGEM_ALTERACAO,STA_DATA_ALTERACAO,STA_CHAVE_RETAGUARDA,STA_VERSAO_RETAGUARDA) values (63946230,1,'16 - Bloqueio Situação de Risco','16',null,null,null,null);
Insert into STATUS (STACOD,STABLC,STADES,STATIPBLOQ,STA_ORIGEM_ALTERACAO,STA_DATA_ALTERACAO,STA_CHAVE_RETAGUARDA,STA_VERSAO_RETAGUARDA) values (63946231,1,'17 - Bloqueio por Restrição de Crédito','17',null,null,null,null);
Insert into STATUS (STACOD,STABLC,STADES,STATIPBLOQ,STA_ORIGEM_ALTERACAO,STA_DATA_ALTERACAO,STA_CHAVE_RETAGUARDA,STA_VERSAO_RETAGUARDA) values (63946232,1,'18 - Bloqueio Cheque Devolvido','18',null,null,null,null);
Insert into STATUS (STACOD,STABLC,STADES,STATIPBLOQ,STA_ORIGEM_ALTERACAO,STA_DATA_ALTERACAO,STA_CHAVE_RETAGUARDA,STA_VERSAO_RETAGUARDA) values (63946233,1,'19- Bloqueio por Cisão','19',null,null,null,null);
Insert into STATUS (STACOD,STABLC,STADES,STATIPBLOQ,STA_ORIGEM_ALTERACAO,STA_DATA_ALTERACAO,STA_CHAVE_RETAGUARDA,STA_VERSAO_RETAGUARDA) values (-1897053128,1,'Crédito recusado na inclusão','20',null,null,null,null);
Insert into STATUS (STACOD,STABLC,STADES,STATIPBLOQ,STA_ORIGEM_ALTERACAO,STA_DATA_ALTERACAO,STA_CHAVE_RETAGUARDA,STA_VERSAO_RETAGUARDA) values (63946221,1,'25 - Bloq. Ações Cob Atr 631/999 dias','25',null,null,null,null);
Insert into STATUS (STACOD,STABLC,STADES,STATIPBLOQ,STA_ORIGEM_ALTERACAO,STA_DATA_ALTERACAO,STA_CHAVE_RETAGUARDA,STA_VERSAO_RETAGUARDA) values (-1895813760,2,'Bloqueio por Atraso','7',null,null,null,null);
Insert into STATUS (STACOD,STABLC,STADES,STATIPBLOQ,STA_ORIGEM_ALTERACAO,STA_DATA_ALTERACAO,STA_CHAVE_RETAGUARDA,STA_VERSAO_RETAGUARDA) values (-1895820037,1,'Cancelamento do Adicional','1',null,null,null,null);
Insert into STATUS (STACOD,STABLC,STADES,STATIPBLOQ,STA_ORIGEM_ALTERACAO,STA_DATA_ALTERACAO,STA_CHAVE_RETAGUARDA,STA_VERSAO_RETAGUARDA) values (-1895820033,1,'Cancelamento cartão danificado','35',null,null,null,null);
Insert into STATUS (STACOD,STABLC,STADES,STATIPBLOQ,STA_ORIGEM_ALTERACAO,STA_DATA_ALTERACAO,STA_CHAVE_RETAGUARDA,STA_VERSAO_RETAGUARDA) values (-1895820034,1,'Cancelamento por erro de impressão','36',null,null,null,null);
Insert into STATUS (STACOD,STABLC,STADES,STATIPBLOQ,STA_ORIGEM_ALTERACAO,STA_DATA_ALTERACAO,STA_CHAVE_RETAGUARDA,STA_VERSAO_RETAGUARDA) values (-1895820035,1,'Cancelamento por erro de leitura','37',null,null,null,null);
Insert into STATUS (STACOD,STABLC,STADES,STATIPBLOQ,STA_ORIGEM_ALTERACAO,STA_DATA_ALTERACAO,STA_CHAVE_RETAGUARDA,STA_VERSAO_RETAGUARDA) values (-1895820036,1,'Cancelamento por perda ou roubo','4',null,null,null,null);
Insert into STATUS (STACOD,STABLC,STADES,STATIPBLOQ,STA_ORIGEM_ALTERACAO,STA_DATA_ALTERACAO,STA_CHAVE_RETAGUARDA,STA_VERSAO_RETAGUARDA) values (-1897053417,2,'Cancelamento por renovação do cartão','56',null,null,null,null);
Insert into STATUS (STACOD,STABLC,STADES,STATIPBLOQ,STA_ORIGEM_ALTERACAO,STA_DATA_ALTERACAO,STA_CHAVE_RETAGUARDA,STA_VERSAO_RETAGUARDA) values (-1895813756,0,'Sem Bloqueio','0',null,null,null,null);
Insert into STATUS (STACOD,STABLC,STADES,STATIPBLOQ,STA_ORIGEM_ALTERACAO,STA_DATA_ALTERACAO,STA_CHAVE_RETAGUARDA,STA_VERSAO_RETAGUARDA) values (-1897131457,2,'Bloqueio por Remessa','51',null,null,null,null);
GO
Insert into PROPRIO (PRPCOD) values (1);
GO
INSERT	INTO  TRIBUTACAO (TRBID, TRBSIM, TRBCOD, TRBDES, TRBALQ, TRBRED, TRBTABB, TRBINC, TRBOBS, TRBREDINT, TRBOBSINT, TRBSISIF, TRBREDSISIF, TRBOBSSISIF, TRBSIMECF, TRBALQECF)
		VALUES ('F00', 'F', '00', 'FONTE', 0, 0, '6', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'F', 0) ;
INSERT	INTO  TRIBUTACAO (TRBID, TRBSIM, TRBCOD, TRBDES, TRBALQ, TRBRED, TRBTABB, TRBINC, TRBOBS, TRBREDINT, TRBOBSINT, TRBSISIF, TRBREDSISIF, TRBOBSSISIF, TRBSIMECF, TRBALQECF)
	    VALUES ('I00', 'I', '00', 'ISENTO', 0, 0, '4', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'I', 0) ;
INSERT	INTO  TRIBUTACAO (TRBID, TRBSIM, TRBCOD, TRBDES, TRBALQ, TRBRED, TRBTABB, TRBINC, TRBOBS, TRBREDINT, TRBOBSINT, TRBSISIF, TRBREDSISIF, TRBOBSSISIF, TRBSIMECF, TRBALQECF)
	    VALUES ('T17', 'T', '17', 'TRIBUTADO 17', 17, 0, '0', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'T', 17) ;
INSERT	INTO  TRIBUTACAO (TRBID, TRBSIM, TRBCOD, TRBDES, TRBALQ, TRBRED, TRBTABB, TRBINC, TRBOBS, TRBREDINT, TRBOBSINT, TRBSISIF, TRBREDSISIF, TRBOBSSISIF, TRBSIMECF, TRBALQECF)
	    VALUES ('T25', 'T', '25', 'TRIBUTADO 25', 25, 0, '0', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'T', 25) ;
INSERT	INTO  TRIBUTACAO (TRBID, TRBSIM, TRBCOD, TRBDES, TRBALQ, TRBRED, TRBTABB, TRBINC, TRBOBS, TRBREDINT, TRBOBSINT, TRBSISIF, TRBREDSISIF, TRBOBSSISIF, TRBSIMECF, TRBALQECF)
	    VALUES ('T07', 'T', '07', 'TRIBUTADO 7', 7, 0, '7', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'T', 7) ;
INSERT	INTO  TRIBUTACAO (TRBID, TRBSIM, TRBCOD, TRBDES, TRBALQ, TRBRED, TRBTABB, TRBINC, TRBOBS, TRBREDINT, TRBOBSINT, TRBSISIF, TRBREDSISIF, TRBOBSSISIF, TRBSIMECF, TRBALQECF)
	    VALUES ('T12', 'T', '12', 'TRIBUTADO 12', 12, 0, '0', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'T', 12);
INSERT	INTO  TRIBUTACAO (TRBID, TRBSIM, TRBCOD, TRBDES, TRBALQ, TRBRED, TRBTABB, TRBINC, TRBOBS, TRBREDINT, TRBOBSINT, TRBSISIF, TRBREDSISIF, TRBOBSSISIF, TRBSIMECF, TRBALQECF)
	    VALUES ('T27', 'T', '27', 'TRIBUTADO 27', 27, 0, '0', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'T', 27) ;
INSERT	INTO  TRIBUTACAO (TRBID, TRBSIM, TRBCOD, TRBDES, TRBALQ, TRBRED, TRBTABB, TRBINC, TRBOBS, TRBREDINT, TRBOBSINT, TRBSISIF, TRBREDSISIF, TRBOBSSISIF, TRBSIMECF, TRBALQECF)
	    VALUES ('T18', 'T', '18', 'TRIBUTADO 18', 18, 0, '0', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'T', 18) ;
GO

INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39100327006666, '2010-10-14 22:00:00', 'version 02.02');
GO

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SP_IMPORTACAO_CLIENTE]') AND type in (N'P', N'PC'))
	DROP procedure "SP_IMPORTACAO_CLIENTE"
GO

create PROCEDURE "SP_IMPORTACAO_CLIENTE"
(
  @V_CLICOD     CHAR,
  @V_CLIDES      VARCHAR,
  @V_CLICPFCGC   CHAR,
  @V_CLIEND    VARCHAR,
  @V_CLIBAI     VARCHAR,
  @V_CLICID     VARCHAR,
  @V_CLIEST     CHAR,
  @V_CLICEP     CHAR,
  @V_CLINUM     VARCHAR,
  @V_CLICMP     VARCHAR,
  @V_CLITEL     VARCHAR,
  @V_STACOD     CHAR,
  @V_CLITABPRZ   CHAR,
  @V_CLIPRZ     numeric(15,2),
  @V_CLIFAN     VARCHAR,
  @V_CLIRGCGF    VARCHAR,
  @V_CLIDTCAD    datetime,
  @V_CLIDTNAS    datetime,
  @V_CLIDTBLO    datetime,
  @V_CLIPFPJ    CHAR,
  @V_CLITEL2    VARCHAR,
  @V_CLIFAX     VARCHAR,
  @V_CLICON     VARCHAR,
  @V_CLIENDCOB   VARCHAR,
  @V_CLIBAICOB   VARCHAR,
  @V_CLICEPCOB   CHAR,
  @V_CLICIDCOB   VARCHAR,
  @V_CLIESTCOB   CHAR,
  @V_CLINUMCOB   VARCHAR,
  @V_CLICMPCOB   VARCHAR,
  @V_CLIDCN     numeric (15,2),
  @V_CLIOBS     VARCHAR,
  @V_CLIRES     VARCHAR,
  @V_CLIEMAIL    VARCHAR,
  @V_CLIDTALT    datetime,
  @V_CLICAE     VARCHAR,
  @V_CLISEX     CHAR,
  @V_CLITIPRES   CHAR,
  @V_CLITMPRES   VARCHAR,
  @V_CLICAR     VARCHAR,
  @V_CLIPNTREF   VARCHAR,
  @V_CLICPREND    CHAR,
  @V_CLICPRRDA    CHAR,
  @V_CLISAL       numeric(15,2),
  @V_CLIOUTRDA    VARCHAR,
  @V_CLIESTCIV    CHAR,
  @V_CLISITAPR    CHAR,
  @V_CLIDIAFEC    CHAR,
  @V_CLINAT       VARCHAR,
  @V_CLIRGEXP     CHAR,
  @V_CLITIPPRC    CHAR,
  @V_RAMCOD       CHAR,
  @V_FUNCOD       CHAR,
  @V_CLICODINT    VARCHAR
 )
AS

begin

   IF	(SELECT COUNT(*) FROM cliente WHERE CLICOD = @V_CLICOD ) > 0

    UPDATE CLIENTE SET CLICOD     = @V_CLICOD,
                       CLIDES     = @V_CLIDES,
                       CLICPFCGC  = @V_CLICPFCGC,
                       CLIEND     = @V_CLIEND,
                       CLIBAI     = @V_CLIBAI,
                       CLICID     = @V_CLICID,
                       CLIEST     = @V_CLIEST,
                       CLICEP     = @V_CLICEP,
                       CLINUM     = @V_CLINUM,
                       CLICMP     = @V_CLICMP,
                       CLITEL     = @V_CLITEL,
                       STACOD     = @V_STACOD,
                       CLITABPRZ  = @V_CLITABPRZ,
                       CLIPRZ     = @V_CLIPRZ,
                       CLIFAN     = @V_CLIFAN,
                       CLIRGCGF   = @V_CLIRGCGF,
                       CLIDTCAD   = @V_CLIDTCAD,
                       CLIDTNAS   = @V_CLIDTNAS,
                       CLIDTBLO   = @V_CLIDTBLO,
                       CLIPFPJ    = @V_CLIPFPJ,
                       CLITEL2    = @V_CLITEL2,
                       CLIFAX     = @V_CLIFAX,
                       CLICON     = @V_CLICON,
                       CLIENDCOB  = @V_CLIENDCOB,
                       CLIBAICOB  = @V_CLIBAICOB,
                       CLICEPCOB  = @V_CLICEPCOB,
                       CLICIDCOB  = @V_CLICIDCOB,
                       CLIESTCOB  = @V_CLIESTCOB,
                       CLIDCN     = @V_CLIDCN,
                       CLIOBS     = @V_CLIOBS,
                       CLIRES     = @V_CLIRES,
                       CLIEMAIL   = @V_CLIEMAIL,
                       CLIDTALT   = @V_CLIDTALT,
                       CLICAE     = @V_CLICAE,
                       CLISEX     = @V_CLISEX,
                       CLITIPRES  = @V_CLITIPRES,
                       CLITMPRES  = @V_CLITMPRES,
                       CLICAR     = @V_CLICAR,
                       CLIPNTREF  = @V_CLIPNTREF,
                       CLICPREND  = @V_CLICPREND,
                       CLICPRRDA  = @V_CLICPRRDA,
                       CLISAL     = @V_CLISAL,
                       CLIOUTRDA  = @V_CLIOUTRDA,
                       CLIESTCIV  = @V_CLIESTCIV,
                       CLISITAPR     = @V_CLISITAPR,
                       CLIDIAFEC     = @V_CLIDIAFEC,
                       CLINAT        = @V_CLINAT,
                       CLIRGEXP      = @V_CLIRGEXP,
                       CLITIPPRC  = @V_CLITIPPRC,
                       RAMCOD        = @V_RAMCOD,
                       FUNCOD        = @V_FUNCOD,
                       CLICODINT     = @V_CLICODINT
                 WHERE CLICOD        = @V_CLICOD;
  ELSE
    INSERT INTO CLIENTE(CLICOD,CLIDES,
                        CLICPFCGC,CLIEND,
                        CLIBAI,CLICID,
                        CLIEST,CLICEP,
                        CLINUM,CLICMP,
                        CLITEL,
                        STACOD,
                        CLITABPRZ,CLIPRZ,
                        CLIFAN,CLIRGCGF,
                        CLIDTCAD,CLIDTNAS,
                        CLIDTBLO,CLIPFPJ,
                        CLITEL2,CLIFAX,
                        CLICON,CLIENDCOB,
                        CLIBAICOB,CLICEPCOB,
                        CLICIDCOB,CLIESTCOB,
                        CLINUMCOB,CLICMPCOB,
                        CLIDCN,CLIOBS,
                        CLIRES,
                        CLIEMAIL,CLIDTALT,
                        CLICAE,CLISEX,
                        CLITIPRES,CLITMPRES,
                        CLICAR,CLIPNTREF,
                        CLICPREND,CLICPRRDA,
                        CLISAL,
                        CLIOUTRDA,CLIESTCIV,
                        CLISITAPR,
                        CLIDIAFEC,
                        CLINAT,CLIRGEXP,
                        CLITIPPRC,RAMCOD,
                        FUNCOD,CLICODINT)
                 values(@V_CLICOD,@V_CLIDES,
                        @V_CLICPFCGC,@V_CLIEND,
                        @V_CLIBAI,@V_CLICID,
                        @V_CLIEST,@V_CLICEP,
                        @V_CLINUM,@V_CLICMP,
                        @V_CLITEL,
                        @V_STACOD,
                        @V_CLITABPRZ,@V_CLIPRZ,
                        @V_CLIFAN,@V_CLIRGCGF,
                        @V_CLIDTCAD,@V_CLIDTNAS,
                        @V_CLIDTBLO,@V_CLIPFPJ,
                        @V_CLITEL2,@V_CLIFAX,
                        @V_CLICON,@V_CLIENDCOB,
                        @V_CLIBAICOB,@V_CLICEPCOB,
                        @V_CLICIDCOB,@V_CLIESTCOB,
                        @V_CLINUMCOB,@V_CLICMPCOB,
                        @V_CLIDCN,@V_CLIOBS,
                        @V_CLIRES,
                        @V_CLIEMAIL,@V_CLIDTALT,
                        @V_CLICAE,@V_CLISEX,
                        @V_CLITIPRES,@V_CLITMPRES,
                        @V_CLICAR,@V_CLIPNTREF,
                        @V_CLICPREND,@V_CLICPRRDA,
                        @V_CLISAL,
                        @V_CLIOUTRDA,@V_CLIESTCIV,
                        @V_CLISITAPR,
                        @V_CLIDIAFEC,
                        @V_CLINAT,@V_CLIRGEXP,
                        @V_CLITIPPRC,@V_RAMCOD,
                        @V_FUNCOD,@V_CLICODINT);

END
GO
-- 39100930090828_start_version_020300.sql
--  alter table ecommerce produto add column preco
-- Migration SQL that makes the change goes here.


INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39100930090828, '2011-06-23 14:02:13', 'start version 020300');

-- 39100930090928_drop_table_ecommerce_produto.sql
--  drop table ecommerce produto
-- Migration SQL that makes the change goes here.
DROP TABLE ECM_PRODUTO;
GO


INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39100930090928, '2011-06-23 14:02:13', 'drop table ecommerce produto');

-- 39100930091043_create_table_ecommerce_produto.sql
--  create table ecommerce produto
-- Migration SQL that makes the change goes here.
CREATE TABLE ECM_PRODUTO
(
EPRID BIGINT IDENTITY (1,1) NOT NULL,
EPRDES varchar(60) NOT NULL,
EPRCAR text,
EPRPOR varchar(50),
EPRREF text,
ECTCOD BIGINT NOT NULL,
EFBCOD BIGINT NOT NULL,
EPRCOD BIGINT NOT NULL,
PRIMARY KEY (EPRID)
)
GO


INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39100930091043, '2011-06-23 14:02:13', 'create table ecommerce produto');

-- 39101026083627_drop_procedure_SP_IMPORTACAO_PRECO.sql
--  alter procedure SP_IMPORTACAO_PRECO
GO
drop procedure SP_IMPORTACAO_PRECO
GO



INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39101026083627, '2011-06-23 14:02:13', 'drop procedure SP IMPORTACAO PRECO');

-- 39101026083905_alter_procedure_SP_IMPORTACAO_PRECO.sql
--  alter procedure SP_IMPORTACAO_PRECO
GO
CREATE PROCEDURE [dbo].[SP_IMPORTACAO_PRECO]
(
  @vCodigoLoja int,
  @vCodigoProduto int,
  @vPrcVenda1 numeric (15,2),
  @vPrcOferta1 numeric (15,2),
  @vPrcVenda2 numeric (15,2),
  @vPrcOferta2 numeric (15,2),
  @vPrcVenda3 numeric (15,2),
  @vPrcOferta3 numeric (15,2),
  @vMargem1 numeric (15,2),
  @vMargem2 numeric (15,2),
  @vMargem3 numeric (15,2),
  @vCusto numeric (15,2),
  @vQtdMinPrc2 numeric (15,2),
  @vQtdMinPrc3 numeric (15,3),
  @vDataUltReaPrc1 datetime,
  @vDataUltReaPrc2 datetime,
  @vDataUltReaPrc3 datetime,
  @vDescontoMaximo numeric (15,2),
  @vPermiteDesconto CHAR
)
AS

begin

 DECLARE @id int
 SELECT @id = MAX(P.PRCID)+1 FROM PRECO P

  IF (SELECT COUNT(*) FROM PRECO WHERE LOJCOD=@vCodigoLoja AND PROCOD = @vCodigoProduto) > 0
      UPDATE PRECO SET
           PRCVDAVAR = @vPrcVenda1,
           PRCOFEVAR = @vPrcOferta1,
           PRCMRG1 = @vMargem1,
           PRCVDA2 = @vPrcVenda2,
           PRCOFE2 = @vPrcOferta2,
           PRCMRG2 = @vMargem2,
           PRCQTDMINPRC2 = @vQtdMinPrc2,
           PRCVDA3 = @vPrcVenda3,
           PRCOFE3 = @vPrcOferta3,
           PRCMRG3 = @vMargem3,
           PRCQTDMINPRC3 = @vQtdMinPrc3,
           PRCCST = @vCusto,
           PRCDTULTRE = @vDataUltReaPrc1,
           PRCDTULTRE2 = @vDataUltReaPrc2,
           PRCDTULTRE3 = @vDataUltReaPrc3,
           PRCDCNMAX = @vDescontoMaximo,
           PRCPERDCN = @vPermiteDesconto
       WHERE LOJCOD = @vCodigoLoja AND PROCOD = @vCodigoProduto;
  ELSE
    INSERT INTO PRECO(LOJCOD,PROCOD,PRCVDAVAR,PRCOFEVAR,PRCMRG1,PRCVDA2,PRCOFE2,PRCMRG2,PRCQTDMINPRC2,PRCVDA3,PRCOFE3,PRCMRG3,PRCQTDMINPRC3,PRCCST,PRCDTULTRE,PRCDTULTRE2,PRCDTULTRE3,PRCDCNMAX,PRCPERDCN)
       values(@vCodigoLoja,@vCodigoProduto,@vPrcVenda1,@vPrcOferta1,@vMargem1,@vPrcVenda2,@vPrcOferta2,@vMargem2,@vQtdMinPrc2,@vPrcVenda3,@vPrcOferta3,@vMargem3,@vQtdMinPrc3,@vCusto,@vDataUltReaPrc1,@vDataUltReaPrc2,@vDataUltReaPrc3,@vDescontoMaximo,@vPermiteDesconto);

END;
GO


INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39101026083905, '2011-06-23 14:02:13', 'alter procedure SP IMPORTACAO PRECO');

-- 39101026084216_drop_procedure_SP_IMPORTACAO_SUBGRUPO_PRODUTO.sql
--  drop procedure SP_IMPORTACAO_SUBGRUPO_PRODUTO
GO
drop procedure SP_IMPORTACAO_SUBGRUPO_PRODUTO;
GO



INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39101026084216, '2011-06-23 14:02:13', 'drop procedure SP IMPORTACAO SUBGRUPO PRODUTO');

-- 39101026084306_alter_procedure_SP_IMPORTACAO_SUBGRUPO_PRODUTO.sql
--  alter procedure SP_IMPORTACAO_SUBGRUPO_PRODUTO
GO
CREATE PROCEDURE [dbo].[SP_IMPORTACAO_SUBGRUPO_PRODUTO]
(
  @vCodigo       int,
  @vCodigoGrupo  int,
  @vCodigoSecao  int,
  @vDescricao    VARCHAR(80)
)
AS

begin
 DECLARE @id int
 DECLARE @grupo_id int

 SET @grupo_id = (SELECT GRPID  FROM GRUPO_PRODUTO  WHERE GRPCOD=@vCodigoGrupo AND SECCOD=@vCodigoSecao)

 IF (@grupo_id > 0)
  IF (SELECT COUNT(*) FROM SUBGRUPO_PRODUTO  WHERE SGPCOD=@vCodigo AND GRPCOD=@grupo_id) > 0
    UPDATE SUBGRUPO_PRODUTO SET SGPDES = @vDescricao
       WHERE SGPCOD=@vCodigo AND GRPCOD=@grupo_id;
  ELSE
    INSERT INTO SUBGRUPO_PRODUTO(SGPCOD, GRPCOD, SECCOD, SGPDES)
       values(@vCodigo, @grupo_id, @vCodigoSecao, @vDescricao);

END;
GO



INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39101026084306, '2011-06-23 14:02:13', 'alter procedure SP IMPORTACAO SUBGRUPO PRODUTO');

-- 39101026084556_drop_procedure_SP_IMPORTACAO_CODIGO_AUXILIAR.sql
--  drop procedure SP_IMPORTACAO_CODIGO_AUXILIAR
GO
drop procedure SP_IMPORTACAO_CODIGO_AUXILIAR
GO



INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39101026084556, '2011-06-23 14:02:13', 'drop procedure SP IMPORTACAO CODIGO AUXILIAR');

-- 39101026084633_alter_procedure_SP_IMPORTACAO_CODIGO_AUXILIAR.sql
--  alter procedure SP_IMPORTACAO_CODIGO_AUXILIAR
GO
CREATE PROCEDURE [dbo].[SP_IMPORTACAO_CODIGO_AUXILIAR]
(
@V_PROCODAUX VARCHAR(20),
@V_PROCOD INT
) AS

begin

  IF	(SELECT COUNT(*) FROM PRODUTOAUX WHERE PROCODAUX = @V_PROCODAUX ) > 0
    update PRODUTOAUX set PROCODAUX = @V_PROCODAUX, PROCOD = @V_PROCOD where PROCODAUX = @V_PROCODAUX;
 else
   insert into PRODUTOAUX(PROCODAUX,PROCOD) values(@V_PROCODAUX,@V_PROCOD);

END;
GO



INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39101026084633, '2011-06-23 14:02:13', 'alter procedure SP IMPORTACAO CODIGO AUXILIAR');

-- 39101026084749_alter_table_Preco.sql
--  alter table Preco
alter table [dbo].[PRECO] add CONSTRAINT [PK_PRECO] PRIMARY KEY CLUSTERED (
	[PRCID] ASC
)
GO


INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39101026084749, '2011-06-23 14:02:13', 'alter table Preco');

-- 39101118070450_alter_table_estoque_column_status_qtd_minima.sql
--  alter table estoque column status qtd minima
-- Migration SQL that makes the change goes here.

ALTER TABLE dbo.ESTOQUE ADD
	ESTSTAECOMMERCE varchar(50) NULL,
	ESTMIN int NULL
GO


INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39101118070450, '2011-06-23 14:02:13', 'alter table estoque column status qtd minima');

-- 39101118073224_alter_table_ecommerce_fabricante_column_descricao_not_null.sql
--  alter table fabricante column descricao not null
-- Migration SQL that makes the change goes here.
BEGIN TRANSACTION
SET QUOTED_IDENTIFIER ON
SET ARITHABORT ON
SET NUMERIC_ROUNDABORT OFF
SET CONCAT_NULL_YIELDS_NULL ON
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
COMMIT
BEGIN TRANSACTION
GO
CREATE TABLE dbo.Tmp_ECM_FABRICANTE
	(
	EFBCOD int NOT NULL IDENTITY (1, 1),
	EFBDES varchar(50) NOT NULL
	)  ON [PRIMARY]
GO
SET IDENTITY_INSERT dbo.Tmp_ECM_FABRICANTE ON
GO
IF EXISTS(SELECT * FROM dbo.ECM_FABRICANTE)
	 EXEC('INSERT INTO dbo.Tmp_ECM_FABRICANTE (EFBCOD, EFBDES)
		SELECT EFBCOD, EFBDES FROM dbo.ECM_FABRICANTE WITH (HOLDLOCK TABLOCKX)')
GO
SET IDENTITY_INSERT dbo.Tmp_ECM_FABRICANTE OFF
GO
DROP TABLE dbo.ECM_FABRICANTE
GO
EXECUTE sp_rename N'dbo.Tmp_ECM_FABRICANTE', N'ECM_FABRICANTE', 'OBJECT'
GO
ALTER TABLE dbo.ECM_FABRICANTE ADD CONSTRAINT
	PK_ECM_FABRICANTE PRIMARY KEY NONCLUSTERED
	(
	EFBCOD
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

GO



INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39101118073224, '2011-06-23 14:02:13', 'alter table ecommerce fabricante column descricao not null');

-- 39101118073404_drop_table_ecommerce_item_nutricional.sql
--  create table ecommerce item nutricional
-- Migration SQL that makes the change goes here.
DROP TABLE ECM_ITEM_NUTRICIONAL
GO



INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39101118073404, '2011-06-23 14:02:13', 'drop table ecommerce item nutricional');

-- 39101118073605_create_table_ecommerce_item_nutricional.sql
--  create table ecommerce item nutricional
-- Migration SQL that makes the change goes here.

CREATE TABLE ECM_ITEM_NUTRICIONAL
	(
	ITNCOD bigint NOT NULL IDENTITY (1, 1),
	ITNDES varchar(50) NOT NULL
	)  ON [PRIMARY]
GO
ALTER TABLE dbo.ECM_ITEM_NUTRICIONAL ADD CONSTRAINT
	PK_ECM_ITEM_NUTRICIONAL PRIMARY KEY
	(	ITNCOD	)
GO



INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39101118073605, '2011-06-23 14:02:13', 'create table ecommerce item nutricional');

-- 39101118073805_insert_all_ecommerce_item_nutricional_descricao.sql
--  insert all ecommerce item nutricional descricao
-- Migration SQL that makes the change goes here.
INSERT INTO ecm_item_nutricional(ITNDES) VALUES ('Valor calórico');
INSERT INTO ecm_item_nutricional(ITNDES) VALUES ('Carboidratos');
INSERT INTO ecm_item_nutricional(ITNDES) VALUES ('Proteínas');
INSERT INTO ecm_item_nutricional(ITNDES) VALUES ('Gorduras totais');
INSERT INTO ecm_item_nutricional(ITNDES) VALUES ('Gorduras saturadas');
INSERT INTO ecm_item_nutricional(ITNDES) VALUES ('Gorduras Trans');
INSERT INTO ecm_item_nutricional(ITNDES) VALUES ('Fibra alimentar');
INSERT INTO ecm_item_nutricional(ITNDES) VALUES ('Cálcio');
INSERT INTO ecm_item_nutricional(ITNDES) VALUES ('Ferro');
INSERT INTO ecm_item_nutricional(ITNDES) VALUES ('Sódio');
GO



INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39101118073805, '2011-06-23 14:02:13', 'insert all ecommerce item nutricional descricao');

-- 39101118074443_alter_table_ecommerce_produto_add_column_preco.sql
--  alter table ecommerce produto add column preco
-- Migration SQL that makes the change goes here.
ALTER TABLE dbo.ECM_PRODUTO ADD	EPRPRC numeric(12, 2) NULL
GO


INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39101118074443, '2011-06-23 14:02:13', 'alter table ecommerce produto add column preco');

-- 39101124063648_drop_table_item_prevenda.sql
--  delete table item prevenda
drop table ITEM_PREVENDA
GO


INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39101124063648, '2011-06-23 14:02:13', 'drop table item prevenda');

-- 39101124064523_create_table_item_prevenda.sql
--  create table item prevenda
CREATE TABLE [dbo].[ITEM_PREVENDA](
	[PRVNUM] [int] NOT NULL,
	[PROCOD] [varchar](14) COLLATE Latin1_General_CI_AS NOT NULL,
	[IPVQTD] [numeric](15, 2) NULL,
	[IPVVLRUNI] [numeric](15, 2) NULL,
	[IPVDCN] [numeric](15, 2) NULL,
	[IPVDCNTIP] [char](1) COLLATE Latin1_General_CI_AS NULL,
	[IPVVLRTOT] [numeric](15, 2) NULL,
	[IPVPRODES] [varchar](45) COLLATE Latin1_General_CI_AS NULL,
	[IPVPRODESRDZ] [varchar](20) COLLATE Latin1_General_CI_AS NULL,
	[IPVTRBID] [char](3) COLLATE Latin1_General_CI_AS NULL,
	[FUNCOD] [varchar](6),
    [IPVPERDCN] [char](1)

 CONSTRAINT [PK_ITEM_PREVENDA] PRIMARY KEY NONCLUSTERED
(
	[PRVNUM] ASC,
	[PROCOD] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO


INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39101124064523, '2011-06-23 14:02:13', 'create table item prevenda');

-- 39101124064858_drop_table_prevenda.sql
--  delete prevenda
DROP TABLE PREVENDA
GO


INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39101124064858, '2011-06-23 14:02:13', 'drop table prevenda');

-- 39101124064913_create_table_prevenda.sql
--  create table prevenda
CREATE TABLE [dbo].[PREVENDA](
	[PRVNUM] [int] NOT NULL,
	[LOJCOD] [int] NULL,
	[TRNDAT] [datetime] NULL,
	[TRNSEQ] [varchar](6) COLLATE Latin1_General_CI_AS NULL,
	[CXANUM] [varchar](3) COLLATE Latin1_General_CI_AS NULL,
	[PRVSTA] [char](2) COLLATE Latin1_General_CI_AS NULL,
	[PRVDATEMI] [datetime] NULL,
	[PRVVLR] [numeric](15, 2) NULL,
	[CLICOD] [int] NULL,
	[PRVCLIDES] [varchar](100) COLLATE Latin1_General_CI_AS NULL,
	[PRVCLIEND] [varchar](100) COLLATE Latin1_General_CI_AS NULL,
	[PRVCLINUM] [varchar](6) COLLATE Latin1_General_CI_AS NULL,
	[PRVCLICMP] [varchar](40) COLLATE Latin1_General_CI_AS NULL,
	[PRVCLIBAI] [varchar](20) COLLATE Latin1_General_CI_AS NULL,
	[PRVCLICID] [varchar](40) COLLATE Latin1_General_CI_AS NULL,
	[PRVCLIEST] [varchar](2) COLLATE Latin1_General_CI_AS NULL,
	[PRVSTAECM] [int] NULL,
	[PRVOBS] [varchar](60) NULL,
	[PRVDATSAI] [datetime] NULL,
	[PRVHORSAI] [datetime] NULL,
	[PRVSTAATU] [char](1),
	[PRVDCN] [numeric](15, 2) NULL,
	[PRVDCNVLR] [numeric](15, 2) NULL,
	[PRVDCNPER] [numeric](15, 2) NULL,
	[PRVCLICEP] [varchar](8) NULL,
	[FUNCOD] [varchar](6) NULL,
	[PRVTIPPRC] [char](1),
	[PRVACR] [numeric](15, 2) NULL,
	[PRVCLITEL] [varchar](12) NULL,

 CONSTRAINT [PK_PREVENDA] PRIMARY KEY CLUSTERED
(
	[PRVNUM] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
ALTER TABLE [dbo].[PREVENDA]  WITH CHECK ADD  CONSTRAINT [FK_PREVENDA_LOJA] FOREIGN KEY([LOJCOD])
REFERENCES [dbo].[LOJA] ([LOJCOD])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[PREVENDA] CHECK CONSTRAINT [FK_PREVENDA_LOJA]
GO


INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39101124064913, '2011-06-23 14:02:13', 'create table prevenda');

-- 39101213062148_alter_table_prevenda_column_formapagamento.sql
--  alter_table_prevenda_column_prvformapag
-- Migration SQL that makes the change goes here.

ALTER TABLE dbo.PREVENDA ADD PRVFORMAPAG int NULL
GO


INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39101213062148, '2011-06-23 14:02:13', 'alter table prevenda column formapagamento');

-- 39101213093728_delete_all_acesso_and_menu.sql
--  delete_all_acesso_and_menu
-- Migration SQL that makes the change goes here.
delete from acesso
GO
delete from menu
GO




INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39101213093728, '2011-06-23 14:02:13', 'delete all acesso and menu');

-- 39101213094346_insert_all_menus_acessos.sql
--  insert_all_menus_acessos
-- Migration SQL that makes the change goes here.
INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (1,0,'Sistema',null,null,null)
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (5,0,'Loja',null,null,null)
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (8,0,'Cliente',null,null,null)
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (17,0,'Produto',null,null,null)
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (21,0,'PDV',null,null,null)
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (24,0,'Pessoal',null,null,null)
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (33,0,'Consulta',null,null,null)
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (52,0,'Integração',null,null,null)
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (62,0,'Relatórios',null,null,null)
	--FILHOS DO RAIZ SISTEMA
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (3,1,'Acesso',null,'acessoForm.cm',null)
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (4,1,'Configuração',null,'configuracaoForm.cm','CONFIGURACAO')
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (2,1,'Parâmetro',null,'parametroForm.cm','PARAMETRO')
	--FILHOS DO RAIZ LOJA
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (6,5,'Loja',null,'lojaForm.cm','LOJA')
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (7,5,'Holding',null,'holdingForm.cm','HOLDING')
	-- FILHOS DE CLIENTE
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (9,8,'Cliente',null,'clienteNovoLayout/clientePopUp.cm','CLIENTE')
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (10,8,'Limite de Crédito',null,null,null)
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (13,8,'Status',null,'statusForm.cm','STATUS')
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (14,8,'Alterar Status',null,'alteraStatusForm.cm','ALTERARSTATUS')
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (15,8,'Ramo',null,'ramoForm.cm','RAMO')
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (16,8,'Cadastro de Senha',null,'clienteSenhaForm.cm','CLIENTESENHA')
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (55,8,'Fidelização',null,null,null)
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (63,8,'Autorizador',null,null,null)
	-- FILHO DE PRODUTO
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (41,17,'Produto',null,'produto/produto.cm','PRODUTO')
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (42,17,'Reajuste',null,null,null)
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (43,17,'Classificação',null,null,null)
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (44,17,'Unidade',null,'unidadeProdutoForm.cm','UNIDADE')
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (45,17,'Impostos',null,null,null)
	-- FILHOS DE PDV
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (22,21,'Finalizadora',null,'finalizadoraForm.cm','FINALIZADORA')
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (23,21,'Tipo de Documento',null,'tipoDocumentoForm.cm','TIPODOCUMENTO')
	-- FILHOS DE PESSOAL
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (25,24,'Funcionário',null,'funcionarioForm.cm','FUNCIONARIO')
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (26,24,'Grupo de Usuário',null,null,null)
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (29,24,'Usuário',null,'usuarioForm.cm','USUARIO')
	-- FILHOS DE CONSULTA
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (51,33,'Estoque',null,'estoque/consulta.cm',null)
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (32,33,'Estatisticas de venda',null,'estatisticas/','ESTATISTICAS')
	--FLILHOS E INTEGRAÇÃO
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (66,52,'Importação',null,null,null)
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (67,52,'Exportação',null,null,null)
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (68,52,'Sincronização',null,'/SysPDVWebSynch/sincronizacao',null)
	-- FILHOS DE lIMITES DE CRÉDITO
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (11,10,'Limite de Crédito',null,'limiteCreditoForm.cm','LIMITECREDITO')
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (12,10,'Autorização',null,'autorizacaoForm.cm','AUTORIZACAO')
	--FILHO DE FIDELIZAÇÃO
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (69,55,'Premios',null,null,null)
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (56,69,'Cadastro',null,'/SysPDVWebFidelizacao/premio/cadastro','CADASTROPREMIO')
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (70,69,'Resgate',null,'/SysPDVWebFidelizacao/premio/resgate','RESGATEPREMIO')
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (71,69,'Estorno',null,'/SysPDVWebFidelizacao/premio/estorno','ESTORNOPREMIO')
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (72,55,'Cartão',null,null,null)
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (57,72,'Gerar Cartão',null,'/SysPDVWebFidelizacao/gerarCartaoFidelizacao','GERACARTAO')
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (58,72,'Consultar Cartão',null,'/SysPDVWebFidelizacao/consultarCartaoFidelizacao','CONSULTACARTAO')
	-- VER COMO VAI FICAR 'NOVAS ABAS' E OUTRO CONTEXTO DESSAS PAGINAS
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (73,55,'Relatórios',null,null,null)
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (74,73,'Extrato',null,'/SysPDVWebFidelizacao/relatorio/extratoDePontos','EXTRATOPONTOS')
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (75,73,'Cartões',null,'/SysPDVWebFidelizacao/relatorio/cartoesPorStatus','CARTOESSTATUS')
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (76,73,'Clientes Inativo',null,'/SysPDVWebFidelizacao/relatorio/clientesInativos','CLIENTESINATIVOS')
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (77,73,'Hábitos de Consumo',null,'/SysPDVWebFidelizacao/relatorio/habitoDeConsumo','HABITOSCONSUMO')
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (78,73,'Cliente em Potêncial',null,'/SysPDVWebFidelizacao/relatorio/clientesEmPotencial','CLIENTESPOTENCIAL')

	-- FIILHO DE REAJUSTE
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (48,42,'Preço',null,'reajuste/preco.cm','PRECO')

	-- FILHO DE CLASSIFICAÇÃO
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (18,43,'Seção',null,'secaoForm.cm','SECAO')
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (19,43,'Grupo',null,'grupoProdutoForm.cm','GRUPOPRODUTO')
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (20,43,'SubGrupo',null,'subGrupoProdutoForm.cm','SUBGRUPOPRODUTO')

	-- FILHOS DE IMPOSTO
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (46,45,'Impostos Federais',null,'impostosFederaisForm.cm','IMPOSTOSFEDERAIS')

	--FILHOS DE GRUPO DE USUARIO
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (27,26,'Grupo de Usuários',null,'grupoUsuarioForm.cm','GRUPOUSUARIO')
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (28,26,'Atribuição',null,'participanteForm.cm','PARTICIPANTE')

	--FILHOS DE USUARIO
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (30,29,'Cadastro de Senha',null,'usuarioForm.cm','USUARIOSENHA')

	-- FILHOS DE RELATÓRIOS
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (36,62,'Cliente',null,'reportCliente.cm','RELATORIOCLIENTE')
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (37,62,'Funcionário',null,'reportFuncionario.cm','RELATORIOFUNCIONARIO')
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (39,62,'Limite de Crédito',null,'reportLimiteDeCredito.cm','RELATORIOLIMITE')
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (54,62,'Ecf',null,'reportEcf.cm','RELATORIOECF')
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (59,62,'Troco Premiado',null,null,null)
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (61,62,'Pré-Pago',null,'reportRankingPrePago.cm','RELATORIOPREPAGO')
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (88,62,'Estoque',null,'reportEstoque.cm','RELATORIOESTOQUE')
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (95,59,'Ranking',null,'reportTrocoPremiadoRanking.cm','RELATORIOTROCOPREMIADORANKING')
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (96,59,'Numeros',null,'reportTrocoPremiado.cm','RELATORIOTROCOPREMIADONUMERO')

	-- FILHOS DE AUTORIZADOR
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (79,63,'Situação',null,'/SysPDVWebAutorizador/cartao/situacao/form','AUTSITUACAO')
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (80,63,'Monitoramento',null,'/SysPDVWebAutorizador/monitoramento/form','AUTMONITORAMENTO')
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (81,63,'Extrato',null,'/SysPDVWebAutorizador/cartao/extrato/form','AUTEXTRATO')
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (82,63,'Relatórios',null,'/SysPDVWebAutorizador/relatorio/form','AUTRELATORIO')

	--FILHOS DE  IMPORTAÇÃO
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (83,66,'Cadastro',null,'/SysPDVWebSynch/importacao/cadastro','CADASTRO')
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (84,66,'Troco Premiado',null,'/SysPDVWebSynch/importacao/trocopremiado','TROCO')
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (85,66,'Cep',null,'/SysPDVWebSynch/importacao/cep','CEP')


--FILHOS DE EXPORTAÇÃO
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (86,67,'Movimentação',null,'/SysPDVWebSynch/exportacao/movimentacao','MOVIMENTACAO')
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (87,67,'Troco Premiado',null,'/SysPDVWebSynch/exportacao/trocopremiado','TROCOPREMIADO')


	--NOVOS FILHOS DE INTEGRAÇÃO
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (89,52,'E-Commerce',null,null,null)
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (90,89,'Categoria', null, '/SysPDVWebECommerce/categoria/form',null)
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (91,89,'Produtos', null,'/SysPDVWebECommerce/produto/form','ECOMPRODUTO')
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (92,89,'Fabricante', null,'/SysPDVWebECommerce/fabricante/form','ECOMFABRICANTE')
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (93,89,'Tabela Nutricional', null, '/SysPDVWebECommerce/produto/tabelanutricional/list','ECOMTABELA')
	INSERT into MENU (MEN_ID,MENPAI,MENNOME,MENORDEM,MENURL,MENROLE) values (94,89,'Monitoramento', null, '/SysPDVWebECommerce/monitoramento/pedidos','ECOMPEDIDOS')

GO
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,1)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,2)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,3)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,4)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,5)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,6)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,7)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,8)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,9)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,10)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,11)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,12)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,13)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,14)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,15)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,16)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,17)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,18)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,19)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,20)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,21)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,22)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,23)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,24)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,25)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,26)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,27)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,28)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,29)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,30)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,32)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,33)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,36)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,37)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,39)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,41)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,42)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,43)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,44)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,45)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,46)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,48)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,51)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,52)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,54)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,55)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,56)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,57)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,58)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,59)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,61)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,62)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,63)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,66)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,67)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,68)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,69)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,70)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,71)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,72)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,73)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,74)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,75)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,76)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,77)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,78)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,79)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,80)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,81)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,82)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,83)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,84)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,85)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,86)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,87)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,88)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,89)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,90)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,91)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,92)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,93)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,94)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,95)
	insert into ACESSO (ACEALTERA,ACEATIVO,ACEEXCLUI,ACEINCLUI,GRPCOD,MEN_ID) values (1,1,1,1,1,96)
GO




INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39101213094346, '2011-06-23 14:02:13', 'insert all menus acessos');

-- 39101221010354_alter_table_ECM_PRODUTO_NUTRICAO.sql
--  alter table ECM_PRODUTO_NUTRICAO
ALTER TABLE dbo.ECM_PRODUTO_NUTRICAO
ALTER COLUMN EPNPERVLRDIA int NULL
GO



INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39101221010354, '2011-06-23 14:02:13', 'alter table ECM PRODUTO NUTRICAO');

-- 39101221011924_alter_table_ECM_PRODUTO_NUTRICAO.sql
--  alter table ECM PRODUTO NUTRICAO
ALTER TABLE [dbo].[ECM_PRODUTO_NUTRICAO]
ALTER COLUMN [EPRCOD] bigint NULL
GO



INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39101221011924, '2011-06-23 14:02:13', 'alter table ECM PRODUTO NUTRICAO');

-- 39110103115406_alter_table_lance_unico_add_column_valor_real.sql
--  alter table lance unico add column valor real
ALTER TABLE dbo.LANCE_UNICO ADD
	VALOR_REAL NUMERIC(18,2) NULL
GO


INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39110103115406, '2011-06-23 14:02:13', 'alter table lance unico add column valor real');

-- 39110104021319_alter_table_loja_add_column_tipo.sql
--  alter table loja add column tipo
-- Migration SQL that makes the change goes here.
ALTER TABLE LOJA ADD LOJTIP VARCHAR(6)
GO


INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39110104021319, '2011-06-23 14:02:13', 'alter table loja add column tipo');

-- 39110111014152_drop_procedure_importacao_produto.sql
--  drop procedure importacao produto
GO
drop procedure "SP_IMPORTACAO_PRODUTO"
GO


INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39110111014152, '2011-06-23 14:02:13', 'drop procedure importacao produto');

-- 39110111020423_create_procedure_sp_importacao_produto.sql
--  create procedure sp importacao produto
GO
CREATE PROCEDURE "SP_IMPORTACAO_PRODUTO"
(
  @V_PROCOD        BIGINT,
  @V_PRODES        VARCHAR(45),
  @V_PRODESRDZ     VARCHAR(20),
  @V_SECCOD        CHAR,
  @V_TRBID         VARCHAR(3),
  @V_PROPESVAR     CHAR,
  @V_PROCOMTIP     CHAR,
  @V_PROCOMCAP     numeric (15,2),
  @V_PROCOMPRO     numeric (15,2),
  @V_PROCOMVEN     numeric (15,2),
  @V_PROVLD        VARCHAR(3),
  @V_LOCCOD        CHAR,
  @V_PROFRTLOJ     CHAR,
  @V_PROESTMIN     numeric (15,3),
  @V_PROESTMAX     numeric (15,3),
  @V_FORCOD        CHAR,
  @V_PROQTDETQ     numeric (15,2),
  @V_PROUNID       VARCHAR(3),
  @V_PROFLGALT     CHAR,
  @V_PROTABA       CHAR,
  @V_PROBONTIP     CHAR,
  @V_PROBONFAT     numeric (15,3),
  @V_PROCTREST     CHAR,
  @V_PRONUMSER     CHAR,
  @V_PROESP        CHAR,
  @V_PROCOMP       CHAR,
  @V_PROENVBAL     CHAR,
  @V_PROCTRVLD     CHAR,
  @V_PRODATCADINC  datetime,
  @V_PRODATFORLIN  datetime,
  @V_PRODATCADALT  datetime,
  @V_FUNCOD        CHAR,
  @V_PROMIX        CHAR,
  @V_PRODESVAR     CHAR,
  @V_PROEND        VARCHAR(20),
  @V_GRPCOD        CHAR,
  @V_SGRCOD        CHAR,
  @V_PROITEEMB     numeric (15,3),
  @V_PROQTDMAXVDA  numeric (15,3),
  @V_PROPESBRT     numeric (9,3),
  @V_PROPESLIQ     numeric (9,3),
  @V_PROUNDREF     CHAR,
  @V_PROMEDREF     numeric (15,3),
  @V_PROFORLIN     CHAR
)
AS

begin

DECLARE @id int
DECLARE @id_secao int
DECLARE @id_grupo int
DECLARE @id_subgrupo int

 SET @id_secao = (SELECT SECID FROM SECAO WHERE SECCOD = @V_SECCOD )

 SET @id_grupo = (SELECT GRPID FROM GRUPO_PRODUTO G WHERE G.GRPCOD = @V_GRPCOD AND G.SECCOD= @V_SECCOD )

 SET @id_subgrupo = (SELECT S.SGPID FROM SUBGRUPO_PRODUTO S WHERE S.SGPCOD = @V_SGRCOD AND S.GRPCOD= @id_grupo )

 IF (@id_secao is null)
	SET @id_secao = 0

   IF (SELECT COUNT(*) FROM PRODUTO WHERE PROCOD=@V_PROCOD) > 0
      UPDATE PRODUTO SET
       PROCOD = @V_PROCOD               ,
       PRODES = @V_PRODES               ,
       PRODESRDZ = @V_PRODESRDZ         ,
       SECCOD = @id_secao               ,
       TRBID = @V_TRBID                 ,
       PROPESVAR = @V_PROPESVAR         ,
       PROCOMTIP = @V_PROCOMTIP         ,
       PROCOMCAP = @V_PROCOMCAP         ,
       PROCOMPRO = @V_PROCOMPRO         ,
       PROCOMVEN = @V_PROCOMVEN         ,
       PROVLD = @V_PROVLD               ,
       LOCCOD = @V_LOCCOD               ,
       PROESTMIN = @V_PROESTMIN         ,
       PROFRTLOJ = @V_PROFRTLOJ         ,
       PROESTMAX = @V_PROESTMAX         ,
       FORCOD = @V_FORCOD               ,
       PROQTDETQ = @V_PROQTDETQ         ,
       PROUNID = @V_PROUNID             ,
       PROBONTIP = @V_PROBONTIP         ,
       PROFLGALT = @V_PROFLGALT         ,
       PROTABA = @V_PROTABA             ,
       PROBONFAT = @V_PROBONFAT         ,
       PROCTREST = @V_PROCTREST         ,
       PROESP    = @V_PROESP            ,
       PRONUMSER = @V_PRONUMSER         ,
       PROCOMP   = @V_PROCOMP           ,
       PROENVBAL = @V_PROENVBAL         ,
       PROCTRVLD = @V_PROCTRVLD         ,
       PRODATCADALT= @V_PRODATCADALT    ,
       FUNCOD    = @V_FUNCOD            ,
       PROMIX    = @V_PROMIX            ,
       PRODESVAR = @V_PRODESVAR         ,
       PROEND    = @V_PROEND            ,
       SGPCOD        = @id_subgrupo     ,
       GRPCOD        = @id_grupo        ,
       PROPESBRT   = @V_PROPESBRT       ,
       PROITEEMB     = @V_PROITEEMB     ,
       PROQTDMAXVDA = @V_PROQTDMAXVDA   ,
       PROPESLIQ     = @V_PROPESLIQ     ,
       PROUNDREF    = @V_PROUNDREF      ,
       PROMEDREF    = @V_PROMEDREF      ,
       PRODATFORLIN  = @V_PRODATFORLIN  ,
       PROFORLIN = @V_PROFORLIN
       WHERE PROCOD = @V_PROCOD;
  ELSE
    INSERT INTO PRODUTO(PROCOD         ,PRODES          ,PRODESRDZ       ,SECCOD          ,TRBID,
          PROPESVAR      ,PROCOMTIP       ,PROCOMCAP       ,PROCOMPRO,
          PROCOMVEN      ,PROVLD          ,LOCCOD,
          PROFRTLOJ       ,PROESTMIN       ,PROESTMAX       ,FORCOD,
          PROQTDETQ       ,
          PROUNID         ,PROFLGALT       ,PROTABA         ,PROBONTIP,
          PROBONFAT      ,PROCTREST       ,PRONUMSER,
          PROESP         ,PROCOMP         ,PROENVBAL       ,PROCTRVLD       ,
          PRODATCADINC    ,FUNCOD          ,PROMIX,
          PRODESVAR      ,PROEND          ,SGPCOD,
          GRPCOD         ,PROITEEMB       ,PROQTDMAXVDA    ,PROPESBRT       ,PROPESLIQ,
          PROUNDREF      ,PROMEDREF       ,PRODATFORLIN    ,PROFORLIN)
       values(@V_PROCOD       ,@V_PRODES        ,@V_PRODESRDZ     ,@id_secao        ,@V_TRBID,
          @V_PROPESVAR    ,@V_PROCOMTIP     ,@V_PROCOMCAP     ,@V_PROCOMPRO,
          @V_PROCOMVEN    ,@V_PROVLD        ,@V_LOCCOD,
          @V_PROFRTLOJ     ,@V_PROESTMIN     ,@V_PROESTMAX     ,@V_FORCOD,
          @V_PROQTDETQ     ,
          @V_PROUNID       ,@V_PROFLGALT     ,@V_PROTABA       ,@V_PROBONTIP,
          @V_PROBONFAT    ,@V_PROCTREST     ,@V_PRONUMSER,
          @V_PROESP       ,@V_PROCOMP       ,@V_PROENVBAL     ,@V_PROCTRVLD     ,
          @V_PRODATCADINC  ,@V_FUNCOD        ,@V_PROMIX,
          @V_PRODESVAR    ,@V_PROEND        ,@id_subgrupo,
          @id_grupo       ,@V_PROITEEMB     ,@V_PROQTDMAXVDA  ,@V_PROPESBRT     ,@V_PROPESLIQ,
          @V_PROUNDREF    ,@V_PROMEDREF     ,@V_PRODATFORLIN  ,@V_PROFORLIN);


       IF (@V_FORCOD <> 0)
	    IF (SELECT COUNT(*) FROM FORNECEDOR WHERE FORCOD=@V_FORCOD) = 0
            insert into FORNECEDOR (FORCOD) values(@V_FORCOD);

             insert into PRODUTO_FORNECEDOR (PROCOD,FORCOD,PRFUNID,PRFQTD,PRFNIVEL)
                values(@V_PROCOD,@V_FORCOD,@V_PROUNID,1,'P');


END
GO


INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39110111020423, '2011-06-23 14:02:13', 'create procedure sp importacao produto');

-- 39110111021023_alter_table_produto_procod_bigint.sql
ALTER TABLE [dbo].[PRODUTO]
ALTER COLUMN [PROCOD] BIGINT NOT NULL
GO


INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39110111021023, '2011-06-23 14:02:13', 'alter table produto procod bigint');

-- 39110111052520_alter_table_produto_fornecedor_procod_bigint.sql
ALTER TABLE [dbo].[PRODUTO_FORNECEDOR]
ALTER COLUMN [PROCOD] BIGINT NOT NULL
GO


INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39110111052520, '2011-06-23 14:02:13', 'alter table produto fornecedor procod bigint');

-- 39110118015410_drop_procedure_importacao_preco.sql
--  drop procedure importacao preco
GO
drop procedure "SP_IMPORTACAO_PRECO"
GO


INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39110118015410, '2011-06-23 14:02:13', 'drop procedure importacao preco');

-- 39110118015615_create_procedure_importacao_preco_procod_bigint.sql
--  create importacao preco procod bigint
GO
CREATE PROCEDURE [dbo].[SP_IMPORTACAO_PRECO]
(
  @vCodigoLoja int,
  @vCodigoProduto bigint,
  @vPrcVenda1 numeric (15,2),
  @vPrcOferta1 numeric (15,2),
  @vPrcVenda2 numeric (15,2),
  @vPrcOferta2 numeric (15,2),
  @vPrcVenda3 numeric (15,2),
  @vPrcOferta3 numeric (15,2),
  @vMargem1 numeric (15,2),
  @vMargem2 numeric (15,2),
  @vMargem3 numeric (15,2),
  @vCusto numeric (15,2),
  @vQtdMinPrc2 numeric (15,2),
  @vQtdMinPrc3 numeric (15,3),
  @vDataUltReaPrc1 datetime,
  @vDataUltReaPrc2 datetime,
  @vDataUltReaPrc3 datetime,
  @vDescontoMaximo numeric (15,2),
  @vPermiteDesconto CHAR
)
AS

begin

 DECLARE @id int
 SELECT @id = MAX(P.PRCID)+1 FROM PRECO P

  IF (SELECT COUNT(*) FROM PRECO WHERE LOJCOD=@vCodigoLoja AND PROCOD = @vCodigoProduto) > 0
      UPDATE PRECO SET
           PRCVDAVAR = @vPrcVenda1,
           PRCOFEVAR = @vPrcOferta1,
           PRCMRG1 = @vMargem1,
           PRCVDA2 = @vPrcVenda2,
           PRCOFE2 = @vPrcOferta2,
           PRCMRG2 = @vMargem2,
           PRCQTDMINPRC2 = @vQtdMinPrc2,
           PRCVDA3 = @vPrcVenda3,
           PRCOFE3 = @vPrcOferta3,
           PRCMRG3 = @vMargem3,
           PRCQTDMINPRC3 = @vQtdMinPrc3,
           PRCCST = @vCusto,
           PRCDTULTRE = @vDataUltReaPrc1,
           PRCDTULTRE2 = @vDataUltReaPrc2,
           PRCDTULTRE3 = @vDataUltReaPrc3,
           PRCDCNMAX = @vDescontoMaximo,
           PRCPERDCN = @vPermiteDesconto
       WHERE LOJCOD = @vCodigoLoja AND PROCOD = @vCodigoProduto;
  ELSE
    INSERT INTO PRECO(LOJCOD,PROCOD,PRCVDAVAR,PRCOFEVAR,PRCMRG1,PRCVDA2,PRCOFE2,PRCMRG2,PRCQTDMINPRC2,PRCVDA3,PRCOFE3,PRCMRG3,PRCQTDMINPRC3,PRCCST,PRCDTULTRE,PRCDTULTRE2,PRCDTULTRE3,PRCDCNMAX,PRCPERDCN)
       values(@vCodigoLoja,@vCodigoProduto,@vPrcVenda1,@vPrcOferta1,@vMargem1,@vPrcVenda2,@vPrcOferta2,@vMargem2,@vQtdMinPrc2,@vPrcVenda3,@vPrcOferta3,@vMargem3,@vQtdMinPrc3,@vCusto,@vDataUltReaPrc1,@vDataUltReaPrc2,@vDataUltReaPrc3,@vDescontoMaximo,@vPermiteDesconto);

END;
GO


INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39110118015615, '2011-06-23 14:02:13', 'create procedure importacao preco procod bigint');

-- 39110118015800_alter_table_preco_drop_constraint_FU_PRECO_LOJA_PRODUTO.sql
--  alter table preco drop constraint FU_PRECO_LOJA_PRODUTO
ALTER TABLE PRECO DROP CONSTRAINT FU_PRECO_LOJA_PRODUTO
GO


INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39110118015800, '2011-06-23 14:02:13', 'alter table preco drop constraint FU PRECO LOJA PRODUTO');

-- 39110118015801_alter_table_preco_procod_bigint.sql
--  alter table preco procod bigint
ALTER TABLE [dbo].[PRECO]
ALTER COLUMN [PROCOD] BIGINT NOT NULL
GO


INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39110118015801, '2011-06-23 14:02:13', 'alter table preco procod bigint');

-- 39110118015802_alter_table_preco_create_constraint_FU_PRECO_LOJA_PRODUTO.sql.sql
--  alter_table_preco_create_constraint_FU_PRECO_LOJA_PRODUTO.sql
ALTER TABLE [PRECO] ADD CONSTRAINT [FU_PRECO_LOJA_PRODUTO] UNIQUE ([PROCOD] ASC, [LOJCOD] ASC)
GO


INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39110118015802, '2011-06-23 14:02:13', 'alter table preco create constraint FU PRECO LOJA PRODUTO');

-- 39110118020131_alter_table_item_venda_procod_bigint.sql
--  alter table item venda procod bigint
ALTER TABLE [dbo].[ITEM_VENDA]
ALTER COLUMN [PROCOD] BIGINT NULL
GO


INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39110118020131, '2011-06-23 14:02:13', 'alter table item venda procod bigint');

-- 39110118020427_alter_table_produtoaux_procod_bigint.sql
--  alter table procoaux procod bigint
ALTER TABLE [dbo].[PRODUTOAUX]
ALTER COLUMN [PROCOD] BIGINT NULL
GO


INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39110118020427, '2011-06-23 14:02:13', 'alter table produtoaux procod bigint');

-- 39110120071001_create_table_VENDA_CONSOLIDADA_FINALIZADORA.sql
--  create table VENDA_CONSOLIDADA_FINALIZADORA
-- Migration SQL that makes the change goes here.
CREATE TABLE VENDA_CONSOLIDADA_FINALIZADORA
(
	ID BIGINT IDENTITY (1,1) NOT NULL,
	LOJCOD int,
	FZDCOD int,
	VCFDAT datetime,
	VCFQTDCLI int,
	VCFVLRTOT numeric(15,2),
	PRIMARY KEY (ID)
)
GO


INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39110120071001, '2011-06-23 14:02:13', 'create table VENDA CONSOLIDADA FINALIZADORA');

-- 39110120071521_create_table_VENDA_CONSOLIDADA_LOJA.sql
--  create table VENDA_CONSOLIDADA_LOJA
-- Migration SQL that makes the change goes here.
CREATE TABLE VENDA_CONSOLIDADA_LOJA
(
	ID BIGINT IDENTITY (1,1) NOT NULL,
	LOJCOD int,
	VCLDAT datetime,
	VCLQTDCLI int,
	VCLVLRTOT numeric(15,2),
	PRIMARY KEY (ID)
)
GO


INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39110120071521, '2011-06-23 14:02:13', 'create table VENDA CONSOLIDADA LOJA');

-- 39110120071838_create_table_VENDA_CONSOLIDADA_PRODUTO_.sql
--  create table VENDA_CONSOLIDADA_PRODUTO
-- Migration SQL that makes the change goes here.
CREATE TABLE VENDA_CONSOLIDADA_PRODUTO
(
	ID BIGINT IDENTITY (1,1) NOT NULL,
	LOJCOD int,
	PROCOD int,
	VCPDAT datetime,
	VCPQTD numeric(15,3),
	VCPVLRTOT numeric(15,2),
	PRIMARY KEY (ID)
)
GO



INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39110120071838, '2011-06-23 14:02:13', 'create table VENDA CONSOLIDADA PRODUTO');

-- 39110120072349_create_trigger_TRI_TRANSACAO_INSERT_.sql
--  create trigger TRI_TRANSACAO_INSERT
-- Migration SQL that makes the change goes here.
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:	<MACIEL, Cleilson>
-- Create date: <13/01/2011>
-- Description:	<Trigger responsavel por popular informacoes
-- 				consolidadas de vendas por LOJA para consultas no SysPDVWeb
-- 				e Aplicativo para iPhone>
-- =============================================
CREATE TRIGGER TRI_TRANSACAO_INSERT ON TRANSACAO
AFTER INSERT
AS
DECLARE @CONTADOR int, @TRNTIP int, @LOJCOD int, @TRNDAT datetime, @TRNVLR numeric(15,2);
BEGIN
  SET NOCOUNT ON;
  select @TRNTIP = TRNTIP, @LOJCOD = LOJCOD, @TRNDAT = TRNDAT, @TRNVLR = TRNVLR from INSERTED;
  IF (@TRNTIP = 1)
  BEGIN
    SET @CONTADOR = 0;
    select @CONTADOR = count(*) from VENDA_CONSOLIDADA_LOJA where LOJCOD = @LOJCOD and VCLDAT = @TRNDAT;
    IF (@CONTADOR = 0)
      insert into VENDA_CONSOLIDADA_LOJA(LOJCOD, VCLDAT, VCLQTDCLI, VCLVLRTOT) values(@LOJCOD, @TRNDAT, 1, @TRNVLR);
    ELSE
      update VENDA_CONSOLIDADA_LOJA set VCLQTDCLI = VCLQTDCLI + 1, VCLVLRTOT = VCLVLRTOT + @TRNVLR where LOJCOD = @LOJCOD and VCLDAT = @TRNDAT;
  END
END
GO


INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39110120072349, '2011-06-23 14:02:13', 'create trigger TRI TRANSACAO INSERT');

-- 39110120072947_create_trigger_TRI_ITEM_VENDA_INSERT.sql
--  create trigger TRI_ITEM_VENDA_INSERT
-- Migration SQL that makes the change goes here.
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:	<MACIEL, Cleilson>
-- Create date: <13/01/2011>
-- Description:	<Trigger responsavel por popular informacoes
--				consolidadas de vendas por PRODUTO para consultas no SysPDVWeb
--				e Aplicativo para iPhone>
-- =============================================
CREATE TRIGGER TRI_ITEM_VENDA_INSERT ON ITEM_VENDA
AFTER INSERT
AS
DECLARE @CONTADOR int, @ITVTIP int, @LOJCOD int, @TRNDAT datetime, @PROCOD int, @ITVVLRTOT numeric(15,2), @ITVQTDVDA numeric(15,3);
BEGIN
  SET NOCOUNT ON;
  select @ITVTIP = ITVTIP, @LOJCOD = LOJCOD, @PROCOD = PROCOD, @TRNDAT = TRNDAT, @ITVVLRTOT = ITVVLRTOT, @ITVQTDVDA = ITVQTDVDA from INSERTED;
  IF (@ITVTIP = 1)
  BEGIN
    SET @CONTADOR = 0;
    select @CONTADOR = count(*) from VENDA_CONSOLIDADA_PRODUTO where LOJCOD = @LOJCOD and VCPDAT = @TRNDAT and PROCOD = @PROCOD;
    IF (@CONTADOR = 0)
      insert into VENDA_CONSOLIDADA_PRODUTO(LOJCOD, VCPDAT, PROCOD, VCPQTD, VCPVLRTOT) values(@LOJCOD, @TRNDAT, @PROCOD, @ITVQTDVDA, @ITVVLRTOT);
    ELSE
      update VENDA_CONSOLIDADA_PRODUTO set VCPQTD = VCPQTD + @ITVQTDVDA, VCPVLRTOT = VCPVLRTOT + @ITVVLRTOT where LOJCOD = @LOJCOD and VCPDAT = @TRNDAT and PROCOD = @PROCOD;
  END
END
GO


INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39110120072947, '2011-06-23 14:02:13', 'create trigger TRI ITEM VENDA INSERT');

-- 39110120074200_create_trigger_TRI_FINALIZACAO_INSERT.sql
--  create trigger TRI_FINALIZACAO_INSERT
-- Migration SQL that makes the change goes here.
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:	<MACIEL, Cleilson>
-- Create date: <13/01/2011>
-- Description:	<Trigger responsavel por popular informacoes
--				consolidadas de vendas por FINALIZACAO para consultas no SysPDVWeb
--				e Aplicativo para iPhone>
-- =============================================
CREATE TRIGGER TRI_FINALIZACAO_INSERT ON FINALIZACAO
AFTER INSERT
AS
DECLARE @CONTADOR int, @LOJCOD int, @TRNDAT datetime, @FZDCOD int, @FZCVLR numeric(15,2);
BEGIN
  SET NOCOUNT ON;
  select @LOJCOD = LOJCOD, @FZDCOD = FZDCOD, @TRNDAT = TRNDAT, @FZCVLR = FZCVLR from INSERTED;
  SET @CONTADOR = 0;
  select @CONTADOR = count(*) from VENDA_CONSOLIDADA_FINALIZADORA where LOJCOD = @LOJCOD and VCFDAT = @TRNDAT and FZDCOD = @FZDCOD;
  IF (@CONTADOR = 0)
    insert into VENDA_CONSOLIDADA_FINALIZADORA(LOJCOD, VCFDAT, FZDCOD, VCFQTDCLI, VCFVLRTOT) values(@LOJCOD, @TRNDAT, @FZDCOD, 1, @FZCVLR);
  ELSE
    update VENDA_CONSOLIDADA_FINALIZADORA set VCFQTDCLI = VCFQTDCLI + 1, VCFVLRTOT = VCFVLRTOT + @FZCVLR where LOJCOD = @LOJCOD and VCFDAT = @TRNDAT and FZDCOD = @FZDCOD;
END
GO


INSERT INTO CHANGELOG (ID, APPLIED_AT, DESCRIPTION) VALUES (39110120074200, '2011-06-23 14:02:13', 'create trigger TRI FINALIZACAO INSERT');

-- 39110120083032_alter_table_estoque_codigo_produto.sql
--  alter table estoque codigo produto
-- Migration SQL that makes the change goes here.
BEGIN TRANSACTION
SET QUOTED_IDENTIFIER ON
SET ARITHABORT ON
SET NUMERIC_ROUNDABORT OFF
SET CONCAT_NULL_YIELDS_NULL ON
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
COMMIT
